Plotting the data if all the data point is to be represented by a vertical bar from the x-axis (y=0) to the value of y for that point
1 回表示 (過去 30 日間)
古いコメントを表示
Ullas Rajvanshi
2016 年 10 月 18 日
コメント済み: Ullas Rajvanshi
2016 年 10 月 18 日
Hi Readers. I have a question regarding matlab. I dont know how to even approach this. Suppose we have a 1D array named y
- we can plot this array with the command plot(y) [this gives a continuous line]
- or with the command scatter(1:numel(y),y,'.') [this shows individual points]
The question is that - how would you plot the same data (y) if every data point is to be represented by a vertical bar from the x-axis (y=0) to the value of y for that point? Hint you will need a for-loop and you can use the index of the for-loop to define the x-position of the vertical bar. Note that each vertical bar can be defined by two points: the two ends on each side.
However I know you can use bar(y) but if you would combine different bar plots in one figure, the one could (partially) hide the other. Then it can sometimes be useful to go 'back to basics’ and draw lines ‘manually’ (i.e. with a basic function like plot() ). Any idea how to do this?
Thanks in advance
0 件のコメント
採用された回答
Matthew Eicholtz
2016 年 10 月 18 日
y = randi(10,1,10); % generate random data
figure;
hold on;
for ii=1:length(y)
plot([ii ii],[0 y(ii)],'b');
end
その他の回答 (1 件)
参考
カテゴリ
Help Center および File Exchange で Discrete Data Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!