NaN matrix and selection rows with 1

use an excel table. some lines belong to two categories (example 1,2) but on matlab I have the symbol NaN. Help. Then in the matrix how can I select together the rows that contain the value 1 with those that have the value 1,2 and 1,3?
<<
>>

5 Kommentare

Jan
Jan am 10 Jan. 2023
Please post the corresponding code you use for importing the Excel file.
the cyclist
the cyclist am 10 Jan. 2023
Posting a few rows of the Excel file (that includes the 1,2 values) might also be helpful.
Alessandro Camillo
Alessandro Camillo am 10 Jan. 2023
.xlsx
Walter Roberson
Walter Roberson am 10 Jan. 2023
What command did you use to read the file?
Image Analyst
Image Analyst am 10 Jan. 2023
If you have any more questions, then attach your .xlsx workbook and code to read it in with the paperclip icon after you read this:

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Dongyue
Dongyue am 12 Jan. 2023

0 Stimmen

You can use readcell() function:
data = readcell('your_file_name')
After that, you need to do some data preprocessing, such as change all the values in that column to string. Then find out whether '1' is in that string, and use this condition to index the row.
However, the best way I can come up with is that, change the datatype for that column into text in you Excel file, and then use readtable() function to import the data.
Walter Roberson
Walter Roberson am 12 Jan. 2023

0 Stimmen

filename = 'sample_mult.csv';
type(filename)
b; n; CAT. TIP. VEG. 2.17E-05; 3.3722; 1 4.33E-05; 6.7443; 1 7.58E-05; 11.803; 2 0.000119; 18.547; 3 0.000163; 25.291; 1, 2 0.000206; 32.035; 1 0.000249; 38.78; 1, 2, 3 0.000293; 45.524; 3, 2
CATvarname = 'CAT. TIP. VEG.';
opt = detectImportOptions(filename, 'VariableNamingRule', 'Preserve');
opt = setvartype(opt, CATvarname, 'char');
data = readtable(filename, opt);
data.(CATvarname) = cellfun(@str2num, data.(CATvarname), 'uniform', 0);
Now you can
has_class = @(CLASS) cellfun(@(Row) ismember(CLASS, Row), data.(CATvarname));
matches1 = has_class(1)
matches1 = 8×1 logical array
1 1 0 0 1 1 1 0

Gefragt:

am 10 Jan. 2023

Beantwortet:

am 12 Jan. 2023

Community Treasure Hunt

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

Start Hunting!

Translated by