How to display stacking circle

1 view (last 30 days)
Shiyun Li
Shiyun Li on 21 May 2020
Answered: Walter Roberson on 22 May 2020
Hi I want to display a stacking circle according to their position in the array and the value in that position will be the number of stacking circle.
for example: if in the 3th place in the array has number 4, it will display 4 circle from the bottom.
Here is my code, I have difficulity on using "circle" so I try to solve the problem use 1 and 0. If you know how to use "circle" in this case please advice.
And What would be the better way to empty the unessary entries in the matrix? (in this case, "1" in the display solution).
% stacking circle
clear;clc;
%initialise an array represent the number of circle in each index position
array=[1 2 3 4 7 1 5 3 1 9 4 6 7 2];
%initialise the maximum value in the array
maxn=max(array);
%creates a ones matrix
stack=ones(maxn,length(array));
%loop through the index in the array
for i=1:length(array)
if array(i)==1
stack(maxn,i)=0;
else
stack(maxn-(array(i)-1):maxn,i)=0;
end
end
disp(stack);
Here is what I had in the command windows, "1" are unessccary.
1 1 1 1 1 1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 1 1 1 0 1 1 1 1
1 1 1 1 0 1 1 1 1 0 1 1 0 1
1 1 1 1 0 1 1 1 1 0 1 0 0 1
1 1 1 1 0 1 0 1 1 0 1 0 0 1
1 1 1 0 0 1 0 1 1 0 0 0 0 1
1 1 0 0 0 1 0 0 1 0 0 0 0 1
1 0 0 0 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
  2 Comments
Geoff Hayes
Geoff Hayes on 22 May 2020
Shiyun - can you provide a picture of what you would like to show? It isn't clear to me what you mean by if in the 3th place in the array has number 4, it will display 4 circle from the bottom.
Shiyun Li
Shiyun Li on 22 May 2020
yes, sorry for the poor decription. here is an example. thank you for replying Geoff

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 22 May 2020
stack = char(' ' + zeros(max(array),length(array)));
stack(ndgrid(max(array):-1:1) <= array) = 'o';

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!