필터 지우기
필터 지우기

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.

조회 수: 1 (최근 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에서 Grid Lines, Tick Values, and Labels에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by