Hi everyone! I can't seem to populate my uitable. I want the first column to be names and the second and third numbers so i do the following:
char1=char(names);
dat={char1 acc sp};
set(handles.uitable1,'Data', dat, 'RowName',num);
,but i get the following error:
Data within a cell array must have size [1 1]
Please help what am i doing wrong? Ive tried setting the Column format to ''char'', but still no luck. Thanks in advance!

 採用された回答

Walter Roberson
Walter Roberson 2012 年 6 月 12 日

3 投票

dat={ cellstr(char1) num2cell(acc(:)) num2cell(sp(:)) };

6 件のコメント

Petya Popova
Petya Popova 2012 年 6 月 13 日
Thanks but now I'm getting
??? Error using ==> set
Values within a cell array must be numeric, logical, or char
I tried using cellstr before and got the same message again...it really is the name column that is the problem, but i can't go without it :/
Walter Roberson
Walter Roberson 2012 年 6 月 13 日
What is class(acc) and class(sp) and class(num) ?
Petya Popova
Petya Popova 2012 年 6 月 13 日
it's one class that stores information about acceleration and speed of sport players. what i did is to get the names:
for i=1:size(all,2)
names(:,i)=all(i).Name;
num(i,1) = all(i).Number;
end
then for the table i just need the maximum values so i do this:
for i=1:size(all,2)
abs1=abs(all(i).Acceleration(:,1));
abs2=abs(all(i).Acceleration(:,2));
temp=abs1+abs2;
acc(i,1) = max(temp);
abs3=abs(all(i).Speed(:,1));
abs4=abs(all(i).Speed(:,2));
temp1=abs3+abs4;
sp(i,1)=max(temp1);
end
char1=char(names);
end the rest is the one posted above...the strange thing is that it works fine if the class has only one object(player) but when they become more it gives that error....
Walter Roberson
Walter Roberson 2012 年 6 月 13 日
dat=[ cellstr(char1) num2cell(acc(:)) num2cell(sp(:)) ];
(Change of {} to [])
Why are you writing the names in as _columns_ instead of rows? You should just construct
names = {all.Name};
and then
dat=[ names(:) num2cell(acc(:)) num2cell(sp(:)) ];
Petya Popova
Petya Popova 2012 年 6 月 13 日
Hey Thanks that worked like a charm!And to answer your question I have to shamefully admit that I'm pretty new to matlab and programing at all.
I thought i needed the columns for the uitable, but i guess I don't really:)
I tried your suggestion, but I also use this to make a legend on the plot and it says it needs to be a string so I put cellstr(names), but then got error in cellstr itself...and it's all very confusing :D
But thanks you've been great help, I think that would work even though it's a bit heavy as I now realize :)
Walter Roberson
Walter Roberson 2012 年 6 月 13 日
When
names = {all.Name};
then to use those names as a legend, use
legend(names{:})

サインインしてコメントする。

その他の回答 (1 件)

cdr
cdr 2015 年 4 月 22 日
編集済み: cdr 2015 年 4 月 22 日

0 投票

Solved the problem:
entered doubles via num2cell(double) and strings via cellstr.
[code] B(i)=cellstr(string1{i});
TE = [num2cell(double1') num2cell(double2) cellstr(B)'] [/code]
Thanks a lot!

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2012 年 6 月 12 日

編集済み:

cdr
2015 年 4 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by