error:Cell elements must be character arrays.
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
wesso Dadoyan
am 19 Jun. 2015
Kommentiert: Image Analyst
am 10 Jul. 2017
Hi ,
I am running a loop : ISIN(i,1)=cusip2isin('US',Cusip91(i)); % I obtained cusip2isin from the file exchange forum. Cusip91(i)='05978R107' when i=1 and gives ISIN(1)='US05978R1077' without any error. but for i=2 , CUSIP91(2)=[463347104] and gives an error: Error using char Cell elements must be character arrays.
Error in cusip2isin (line 25) cusip=char(cusip);
I am wondering how to get rid of this error? I am not very familiar with char and cell arrays. Any help is greatly appreciated
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 19 Jun. 2015
Why is cell #1 a string, '05978R107', while cell #2 is a double scalar,[463347104]? Evidently that File Exchange function wants a cell that contains a string, not a cell that contains a double. You can convert to a string doing something like
if isnumeric(CUSIP91{i})
% Contents of cell are a number.
% Extract number, convert to a string
% then stick back into a cell.
thisCell = {num2str(CUSIP91{i})};
else
% The cell already contains a string so nothing to do.
thisCell = CUSIP91(i);
end
% Now call with a cell that has a string inside of it.
ISIN(i,1)=cusip2isin('US', thisCell);
For a good intuitive explanation of cells, see the DAQ: http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F
2 Kommentare
AHawk
am 10 Jul. 2017
Hello I am using this answer on an empty cell I created and am still getting an error message. My code is as follows
t1 = 1;
[~,y] = size(Data);
for k = 1:length(Data)
NewMatrix = cell(1,y);
if isnumeric(NewMatrix{1i})
thisCell = {num2str(NewMatrix{1i})};
else
thisCell = NewMatrix(1i);
end
char(NewMatrix);
But I am getting the following error message
'Subscript indices must either be real positive integers or logicals.' for this line of code 'if isnumeric(NewMatrix{1i})'
Image Analyst
am 10 Jul. 2017
1i is the imaginary variable "i" = sqrt(-1). You cannot use this as an array index.
In this line:
if isnumeric(NewMatrix{1i})
And why should NewMatrix have anything in it when you just created it? It won't, it will be a row vector of "y" empty cells.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Conversion 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!