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

7 views (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
David Stewart
David Stewart on 20 Jul 2021
Unfortunately this didn't work for me. Fortunately, one of my coworkers who knows matlab showed me my error - I was using a table object from the app, not the actual table itself. At least that's what he told me. I'm still a beginner. Thank you for your help!
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)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!