How to display stacking circle
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Geoff Hayes
2020-5-22
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.
回答(1 个)
Walter Roberson
2020-5-22
stack = char(' ' + zeros(max(array),length(array)));
stack(ndgrid(max(array):-1:1) <= array) = 'o';
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!