error:Cell elements must be character arrays.
31 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Image Analyst
2015 年 6 月 19 日
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 件のコメント
AHawk
2017 年 7 月 10 日
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
2017 年 7 月 10 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!