필터 지우기
필터 지우기

Error using cellstr. Shows error for element that doesn't exist.

조회 수: 16 (최근 30일)
Jannat Manchanda
Jannat Manchanda 2020년 8월 19일
편집: Fangjun Jiang 2020년 8월 20일
I am getting the following error:
Error using cellstr (line 44) Element 154 is not a string scalar or character array. All elements of cell input must be string scalars or character arrays.
But the array I am trying to conver has size: [153 4]
I am trying to display the data to MATLAB Table (App Designer).
I am saving the data into a cell matrix form then converting to string to display in a table in the app.
TblAllInfo=[app.FMain',ChannelNameFinal',LocationFinal',ChannelFilter'];
app.UITableAll.Data=cellstr(TblAllInfo);

답변 (3개)

Fangjun Jiang
Fangjun Jiang 2020년 8월 19일
I can duplicate the error using this simple example. So the problem is TblAllInfo{1,2}. It is the 154th element. It is not a char array.
a =
3×2 cell array
{'a'} {[1]}
{'a'} {[2]}
{'c'} {[3]}
>> cellstr(a)
Error using cellstr (line 44)
Element 4 is not a string scalar or character array. All elements of cell input must be string
scalars or character arrays.
  댓글 수: 2
Jannat Manchanda
Jannat Manchanda 2020년 8월 19일
Yes, exactly this. How to resolve it ?
Fangjun Jiang
Fangjun Jiang 2020년 8월 20일
편집: Fangjun Jiang 2020년 8월 20일
The method depends on the data types. Why don't you show some example data?
In my example data, you could use cellstr(string(a))

댓글을 달려면 로그인하십시오.


Jannat Manchanda
Jannat Manchanda 2020년 8월 19일
For now I have added the following code, so that I can proceed with my work. If anyone has any better answers. TIA :)
for i=1:length(TblAllInfo)
Data1{i}=string(TblAllInfo(i,:));
Data2{i,:}=cellstr(Data1{1,i});
Data3(i,:)=Data2{i};
end
app.UITableAll.Data=Data3;

Walter Roberson
Walter Roberson 2020년 8월 20일
app.UITableAll.Data=cellstr(TblAllInfo(:,1));

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by