Problem with indexing in structures

1 回表示 (過去 30 日間)
Dionisio Mendoza
Dionisio Mendoza 2021 年 9 月 6 日
コメント済み: Dionisio Mendoza 2021 年 9 月 8 日
Hi there!
I am practicing the index on structures. I am trying to find a specific column of a structure using "strcmp".
In the following lines of code I load the file, I make a variable of the headers and in the Genesnumber variable I save the data of the Gene Symbol column belonging to myData
myData=importdata('xd.xlsx','\t')
Error using importdata (line 139)
Unable to open file.
headers=myData.textdata(1,:);
Genesnumber=myData.textdata(:,strcmp('Gene Symbol',headers));
Now I am trying to do the same (extract the data from a specific column) but with the HAGRID header. This HAGRID column in the original file is in column number 2 exactly like the header variable.
So when I test this code the new variable is either empty or with NaN values. That means the column is moving, but I don't know how to fix that little problem.
a=myData.textdata(:,strcmp('HAGRID',headers));
a=myData.data(:,strcmp('HAGRID',headers)); %here change textdata for data

採用された回答

Matt J
Matt J 2021 年 9 月 6 日
編集済み: Matt J 2021 年 9 月 6 日
A table would be handier here than a struct:
myData=readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/730869/xd.XLSX');
Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.
myData.HAGRID
ans = 21×1
139 78 255 187 264 135 35 195 102 138
  1 件のコメント
Dionisio Mendoza
Dionisio Mendoza 2021 年 9 月 8 日
Thank you, i appreciate it. :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by