Azzera filtri
Azzera filtri

Plotting data based on rows from an excel sheet with legends as First element of the row

2 visualizzazioni (ultimi 30 giorni)
Hello, i am trying to plot data that has three variables involved. Plotting depth on y axis, Temperature on X axes. Time which is the first column of my data and also the series name (legend also) as temperature vs depth are being plotted per time. Attached is what i want to do from excel. My code;
UNIQUE_ID_unique = unique(alldata(:,4));
Idx = strcmp(alldata(:,4),UNIQUE_ID_unique(1,1));
subdata = alldata(Idx,:);
test_date_unique = unique(subdata(:,8));
for i=1:length(test_date_unique)
Idxdate = strcmp(subdata(:,8),test_date_unique(i,1));
cols = [22, 23:27, 32:37];
subdata2= subdata(Idxdate,cols);
for n=1:size(subdata2,1)
subdata3(n,1) = str2num(subdata2{n,1});
subdata3(n,2:7) = [0, cell2mat(subdata2(n, 2:6))];
subdata3(n,8:13) = [cell2mat(subdata2(n, 12)), cell2mat(subdata2(n, 7:11))];
end
subdata3sorted = sortrows(subdata3,1);
xval = subdata3sorted(:,8:13)';
yval = subdata3sorted(:,2:7)';
leg = [ ];
for m = 1:size(subdata3sorted,1), leg{m} = num2str(subdata3sorted(m,1)); end
plot(xval,yval,'.-'), set(gca,'ydir','reverse'),xlabel('Temp (F)'),ylabel('Depth (inch)'), legend(leg,'location','southoutside','FontSize',8,'NumColumns',5)
end
But somehow the plots i get reuse previous data i.e. if a plot used 5 pairs of x & y values for say 10 rows, then if the next plot were to plot 5 pairs again, for 8 rows, it somehow change the 8 values and uses the two earlier values. So i end up al the plots with the maximum (time data) plotted over each plot. Can someone help.
  2 Commenti
Hamad Bin Muslim
Hamad Bin Muslim il 8 Nov 2019
Hi, Thanks brother for being ready to help. I figured the bug out. I was not emptying the variables before each loop. That's why it kept old data in the variables and was plotting it.

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by