I try to plot 2 variables against each other selected by user input. But I can not figure it out. I am new to this, not much coding experience.

2 Ansichten (letzte 30 Tage)
% Button pushed function: CheckButton
function CheckButtonPushed(app, event)
%create plot function
t = readtimetable("weather.csv"); %to read table
vars = {'HP','0/100mphsec'};
%get the selected model
selectedModel = app.SelectModelDropDown1.Value;
%find the index of the model in the table
[idx,~] = find(ismember(app.carData2{:,2}, selectedModel));
x = table2array(t(idx,'HP')); %(%specify collumn to assign x));
y = table2array(t(idx,'0/100mphsec')); %(%specify collumn to assign y));
plot (app.UIAxes,x,y);

Antworten (1)

Ishan
Ishan am 30 Nov. 2022
Hi Daniel,
I understand you are trying to plot two variables against each other from a table. You can refer to the following documentation for help with using the plot function: -
However, in your case I observe you are getting an error “unrecognized variable name ‘Data’” which I couldn’t locate in your xlsx file either. If you want to plot data from a table, you can simply store all elements of that particular row or column index you desire in a vector and plot them using the MATLAB plot function. (Do note that A = table2array(T) converts the table or timetable, T, to a homogeneous array, A. The variables in T become columns in A. So, the indexing needs to be done accordingly)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by