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

조회 수: 2 (최근 30일)
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
dpb
dpb 2019년 11월 8일
Be simpler to illustrate if you would just attach the data...
Hamad Bin Muslim
Hamad Bin Muslim 2019년 11월 8일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by