plotting line graph in different colors using while loop
显示 更早的评论
I have a variable called "data" that's a set of data that's 49 rows x 40 columns. time is the first column (data(:,1)) and I want to plot time against the second column of the data (data(:,2)). When the the values in the second column are in certain ranges, I want the line of the line graph to be different colors. I wrote a while/ if else statement to do this, but it's not plotting anything and I'm not sure why. My code is written below. Thank you in advance!
figure
p = 1 %row that's changing (40 rows in all)
w = 2 %sensor/column number
hold on
while p <=size(data,1) %size of column
if data(p,w)<2.65
plot(data(p,1),data(p,2),'g')
elseif data(p,w)>=2.65 & data(p,w)<3.975
plot(data(p,1),data(p,2),'y')
else data(p,w)>=3.975
plot(data(p,1),data(p,2),'r')
end
p = p+1
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Orange 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!