MATLAB: How to line graph from different excel sheet once for all sheet

graphplottingxlsreadxlswrite

%lets say for sheet A
X=1:20; (same for all Sheets)
% Y1, Y2, Y3 values from columns VBV,VYV,VRV respectively which will be different for all sheets
figure1
plot(X,Y1,X,Y2,X,Y3)
title("for sheet A")
% similarly plot for all sheets using for loop
I had a excel file with different data in 5 different sheets, Now I want to plot line graph for all sheets at once running the program using loop or something like this. How can I do this ? Can I also extract these plots in excel sheets? thanks

Best Answer

xlfile = 'NNDTV.xlsx';
[~, sheets] = xlsfinfo(xlfile); %get list of sheets in workbook
X = (1:20)'; %as a column vector for easier plot command
for sh = sheets %iterate over the sheets
shname = sh{1};
value = xlsread(xlfile, shname); %no need to get txt and DT1 if you don't use them
figure;
plot(X, value(:, 1:3)); %if value has only three columns, then simply: plot(X, value);
xlabel('Time');
ylabel('Voltage');
title(sprintf('Sheet %s', shname));
end