MATLAB Answers

How do I make a smaller table by filtering a larger one?

1 view (last 30 days)
I'm making an application that allows you to read a table from a tab delimited text file, select a row from that table, and the app displays a graph based on some data taken from that text file.
The FiberCheckTable is uploaded in a different section of the code, and the serial number (SN) is stored in column 2. The program should then show a stacked plot of the data that is stored in columns 13-16 for that specific SN. What am I doing wrong??
Here's what I have so far:
function FiberSelect(app, event)
% automatically selects serial number (SN) based on cell selected in table
indices = event.Indices;
app.SN = app.FiberCheckTable.Data{indices(1),2};
app.EvaluateCalibration(event);
end
function EvaluateCalibration(app, event)
% graph wavelength of xyz sensors in process
app.Wavelength = app.FiberCheckTable;
app.Wavelength = app.Wavelength(app.Wavelength(:,2)==app.SN,:);
app.Wavelength = sortrows(app.Wavelength,'SerialNumber','ascend');
app.WavelengthAxes = stackedplot(app.Wavelength(:,13:16));
end

Accepted Answer

Image Analyst
Image Analyst on 20 Jul 2021
You might need braces instead of parentheses to get the CONTENTS of the table:
% Determine which rows to extract from the table.
rowsToExtract = app.Wavelength{:,2} == app.SN; % Should be a logical vector (1/0, true/false).
% Extract only those particular rows.
app.Wavelength = app.Wavelength(rowsToExtract, :);
  2 Comments
Image Analyst
Image Analyst on 21 Jul 2021
There is a UI control -- a table or uitable -- that is like a widget you place on the form. That is a different beast than a variable type called a table in MATLAB. So the widget is like a listbox or button or any other widget, while a table variable is like a double, structure, cell array, etc. type of variable. So I guess you were getting confused between the table control and the table variable -- they're different things.

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by