NaN matrix and selection rows with 1
    조회 수: 2 (최근 30일)
  
       이전 댓글 표시
    
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
  Image Analyst
      
      
 2023년 1월 10일
				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:
답변 (2개)
  Dongyue
    
 2023년 1월 12일
        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.
댓글 수: 0
  Walter Roberson
      
      
 2023년 1월 12일
        filename = 'sample_mult.csv';
type(filename)
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)
댓글 수: 0
참고 항목
카테고리
				Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





