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

2 visualizaciones (últimos 30 días)
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 comentarios
dpb
dpb el 8 de Nov. de 2019
Be simpler to illustrate if you would just attach the data...
Hamad Bin Muslim
Hamad Bin Muslim el 8 de Nov. de 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.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Exploration en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by