How to get a string from a cell array given a row?
4 views (last 30 days)
Show older comments
I have error messages from a vehicle that I want to plot on a map. I can already plot them but until now I had to type the exact message in a inputdlg box that opens when I run the script. There are hundreds of messages the vehicle records in this one csv but only a handful of them are errors, and only some of those errors are worth looking at. To make things more complicated the messages are not linked to a lat and long, it has a time stamp but the time stamp for error messages and the lat/long csv is slightly different. So right now I type the exact error I want to plot and the script does the rest and plots the error on top of my tracks.
To streamline this I want to include a list of available errors that might be in the list using listdlg. The rest of my code is looking for string variables so I want to keep it that way. When I use listdlg, it creates a new variable indx, which is the number selected from the list. For instance: I select the first option in listdlg and indx = 1. Now what I want to do is use that number to correlate to a string varible in my list. My thought here is if indx = 1 then I want to extract the string variable from the first row of the list of strings. How can I do this in a for loop? Below is my code and the error that im getting. Thanks!!
errorlist = {'New mission', 'New rally', 'GPS 1: detected as NMEA at 115200 baud', ...,
'EKF3 IMU0 is using GPS', 'EKF3 IMU1 is using GPS', 'AHRS: EKF3 active', 'EKF3 IMU0 MAG0 in-flight yaw alignment complete', ...,
'EKF3 IMU1 MAG0 in-flight yaw alignment complete', 'AHRS: DCM active', 'SmartRTL Low on space!', 'EKF3 lane switch 0', ...,
'EKF3 lane switch 1', 'Flight mode change failed', 'SmartRTL deactivated: buffer full'};
[indx, tf] = listdlg('ListString', errorlist);
errorlist = errorlist.';
errornumel = numel(indx);
for k = 1:errornumel
code = find(errorlist = indx(k));
end
This is the error that I get:
Error using find
Incorrect number or types of inputs or outputs for function find.
Error in list (line 11)
code = find(errorlist = indx(k));
0 Comments
Accepted Answer
More Answers (1)
dpb
on 14 Mar 2025
Edited: dpb
on 14 Mar 2025
"......I select the first option in listdlg and indx = 1. Now what I want to do is use that number to correlate to a string varible in my list. "
code = find(errorlist = indx(k));
isn't the way, what you want to do is to match the string value of the indx value returned of the Value of the listdlg; the indices in the dialog are irrelevant to the location of the messages in the data file. The error is because the errorlist is a cellstr array while index is a numeric value.
ix=arrayfun(@(c)contains(YOURERRORLISTARRAY,errorlist(indx)),'uni',0);
will return the logical vector of which rows contain the selected values although if you want to treat multiple conditions individually rather than in the sequence they're found in the file, then you will want to iterate over the number of indices returned.
Attaching a representative data file would allow actual testing instead of guessing...
0 Comments
See Also
Categories
Find more on Blackman in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!