Why am I getting this error when trying to show a cell of an array? "Brace indexing is not supported for variables of this type"
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Rebeca Lopez
am 25 Feb. 2021
Kommentiert: Rebeca Lopez
am 26 Feb. 2021
Hi, I'm trying to make a code for reading an array (dat) from a text file and changing each cell per column and per row according to a rule. But when I try to use braces to show a specific cell, for example:
hi=dat{5,3}
It shows this error: "Brace indexing is not supported for variables of this type".
So I can't even start making loops changing the values of the cells because it's not even allowing me to use braces for a specific cell.
Here's the code I used for reading the text and converting to an array:
rap = yourfolder; %'path of folder where my file is located'
fnm = fullfile(rap,'sh_day.txt');
fmt = repmat('%f',1,301);
opt = {'HeaderLines',3, 'CollectOutput',true,'Delimiter',','};
[fid,msg] = fopen(fnm,'rt');
assert(fid>0,msg)
dat = textscan(fid, fmt, opt{:});
fclose(fid);
dat = dat{1};
Thanks!
2 Kommentare
Simon Allosserie
am 26 Feb. 2021
Bearbeitet: Simon Allosserie
am 26 Feb. 2021
Is that value on location (5,3) in dat actually a cell? You use {} for selecting cells. If you select the cell content, you need to use ().
Akzeptierte Antwort
Stephen23
am 26 Feb. 2021
dat is numeric, so you need to use parentheses:
hi = dat(5,3)
I already explained this in more detail in my response to your comment:
0 Kommentare
Weitere Antworten (1)
Walter Roberson
am 26 Feb. 2021
Bearbeitet: Walter Roberson
am 26 Feb. 2021
Your file has no data (after at most 3 header lines). The textscan result is empty.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Text Data Preparation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!