How to plot selected choices

6 views (last 30 days)
Sean St Cyr
Sean St Cyr on 13 Nov 2020
Commented: Peter Perkins on 19 Nov 2020
I have the code below that give the user a dialoug box to choose a material that is read in from an excel file and turned into a table. The user can selected as many materials as they want. However Im lost on how to match up the Materials selected and the data sets thats on the other page of the excel file. All of this without hardcoding it. Ill attach my entire code but im looking at the code after the line
if strcmp(choice,'Detail')
after that line im looking to plot the selected material and corect data set..Heres the enitre code i have
Information = readtable("Cooling Data.xlsx",'Sheet',"Information"); %Reads in the Information
Data = readmatrix('Cooling Data.xlsx','Sheet',"Data"); %Reads in the Data
choice = questdlg('What type of plot do you want to create?','Plot','Summary','Detail','Detail'); %Makes the User select an option
if strcmp(choice,'Summary')
for d = 1:2:size(Data)
x = Data(d,:);
y = Data(d+1,:);
plot(x,y,'*') %Plot data
hold on
xlim([0 10]) %Sets x axis from 0-10
ylim([0 100]) %Sets y axis from 0-100
xlabel('Time (t) [min]'); %X-axis label
ylabel('Temperature difference (T) [°C]'); %Y-axis label
title('Summary Plot'); %Title of graph
legend('Steel','Aluminum','Copper','Nylon','Silicon Rubber','Lead'); %Legend of plotted points
grid on %Turns grid on
end
end
if strcmp(choice,'Detail')
selection = listdlg("PromptString",'Choose a material', "ListString", Information.Material) %prompts the list dialoug box
mat = Information.Material(selection) % stores selection in variable mat
[a,s] = size(Data);
plot(x,y,'d') %Plot data
xlim([0 10]) %Sets x axis from 0-10
ylim([0 100]) %Sets y axis from 0-100
xlabel('Time (t) [min]'); %X-axis label
ylabel('Temperature difference (T) [°C]'); %Y-axis label
title('Detailed Plot'); %Title of graph
legend(mat) %legend of material(s) selected
hold on
grid on
choice = questdlg('What type of plot do you want to create?','Plot','Summary','Detail','Stop','Stop'); %Makes the User select an option
end
  2 Comments
Geoff Hayes
Geoff Hayes on 13 Nov 2020
Sean - how is the data in the Data sheet of Cooling Data.xlsx organized especially with respect to the materials from the Information sheet?
Peter Perkins
Peter Perkins on 19 Nov 2020
Sean, this
for d = 1:2:size(Data)
may work, but size returns (at least) a two-element vector. Maybe size(Data,1), i.e. height(Data)?
This is probably not realted to your actual question, but from these
x = Data(d,:);
y = Data(d+1,:);
it looks like your data are row-oriented, which I guess is why you are not using readtable (which is column-oriented). Still, you might consider transposing what you've read in, converting to a table, and converting the odd numbered variables in the table to durations. If all you are doing is plotting, it probably doesn't make things easier, but if you're doing something next, it might.

Sign in to comment.

Answers (0)

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!