error:Cell elements must be character arrays.
조회 수: 40 (최근 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!