plotting line graph in different colors using while loop
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Annotations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!