open cell array/structure

I have a .m file of cell array that I want to set in a uitable data, but the following error appears:
??? Error using ==> set Values within a cell array must be numeric, logical, or char
Then i repaired that the program open the file but in the format:
Data =
{30x5 cell}
Not as a matrix.
Because the matrix has strings, and I want to set them in the uitable too, I can use the function cell2mat.
In fact, when I open the .m file it comes as a structure array, but I changed it to a cell array because i thought it would be better.. can someone help me?

 채택된 답변

Guilherne
Guilherne 2011년 10월 9일

0 개 추천

As I said, the above error appears, I think that occurs because the matlab doesnt read the matrix, just a "{30x5 cell}". Whem my file only had numbers, i could use "cell2mat", then it becomes a matrix to matlab and the set worked well.

댓글 수: 6

Fangjun Jiang
Fangjun Jiang 2011년 10월 9일
The error message is clear. "Values within a cell array must be numeric, logical, or char". use celldisp(Data) or open('Data') to check the value of Data. Does it contain values other than numerical, logical or char?
Guilherne
Guilherne 2011년 10월 9일
It contain:
'w' '5' '9' '0' '8'
'h' '7' '8' '9' '5'
before, it just had numbers, so i could use cell2mat. Now i cant set the data in the uitable:
before:
%saving
table_1 = get(handles.Tabela_Propriedades,'Data');
table = str2double(table_2);
uisave('table','dados');
%opening
[filename, path] = uigetfile('*.mat','Select the MATLAB code file');
Dados_1 = open([path filename]);
Dados = cell2mat(struct2cell(Dados_1));
set(handles.Tabela_Propriedades,'Data',Dados);
Now, I also have strings im my matrix, so i cant convert to double when I save, neither use cell2mat when opening.
Fangjun Jiang
Fangjun Jiang 2011년 10월 9일
You don't need to do any converstion. Just do:
%saving
table_1 = get(handles.Tabela_Propriedades,'Data');
uisave('table_1','dados');
%opening
[filename, path] = uigetfile('*.mat','Select the MATLAB code file');
Dados_1 = open([path filename]);
Dados = Dados_1.table_1;
set(handles.Tabela_Propriedades,'Data',Dados);
Walter Roberson
Walter Roberson 2011년 10월 9일
Guilherne, if that was what your cell Data contained, then MATLAB would not be telling you it is a 30 x 5 cell array.
Perhaps it instead contains
{'w'} {'5'} {'9'} {'0'} {'8'}
{'h'} {'7'} {'8'} {'9'} {'5'}
??
Guilherne
Guilherne 2011년 10월 9일
Thanks man! i didnt know i could use the data that way (Dados = Dados_1.table_1; ), problem solved, thank you again because of the patience with me and my terrible english!
Guilherne
Guilherne 2011년 10월 9일
Walter, that happened because my uitable size is 30x5, and it saves even the blank spaces, I think.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2011년 10월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by