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 次查看(过去 30 天)
% 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);

回答(1 个)

Ishan
Ishan 2022-11-30
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)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by