why wont uitable accept this text

1 view (last 30 days)
Jason
Jason on 4 Feb 2015
Commented: Jason on 5 Feb 2015
I have an array (using vertcat) that I want to insert into a uitable.
B =
R01C01
R01C01
R01C01
R01C01
R01C02
R01C02
R01C02
R02C01
Why does the following not work?
dataTest(:,1)=B;
% dataTest(:,2)=C;
% dataTest(:,3)=S;
% dataTest(:,4)=St;
% dataTest(:,5)=Ed;
set(handles.uitable2,'data',dataTest);
I have rem'd out the other columns, but eventually I will want these too, they are all integers.
  2 Comments
Jan
Jan on 4 Feb 2015
Please explain the details. What is the class of "B"? It could be a CHAR matrix or a cell string. What is the class of dataTest? What exactly does "not work" mean? Do you get an error message? If so, please take the time to copy it completely and insert it in your question. This is much more efficient than letting us guess the details. Thanks.
Jason
Jason on 4 Feb 2015
Hi, the class of B is char, and class of the rest is double. The error mesage is:
Subscripted assignment dimension mismatch.
Error in myfunction (line 197)
dataTest(:,1)=B;

Sign in to comment.

Accepted Answer

Geoff Hayes
Geoff Hayes on 5 Feb 2015
Jason - what has dataset been initialized too? If I set B as
B = [
'R01C01'
'R01C01'
'R01C01'
'R01C01'
'R01C02'
'R01C02'
'R01C02'
'R02C01']
and then (without initializing) set dataTest to
dataTest(:,1)=B;
I observe the same error message because I am only setting the first column of dataTest whereas B has six columns. Hence the mismatch - trying to push six columns into one. The following would work
dataTest(:,1:6)=B;
but that isn't really what you want. I suspect that you want to be using a cell array as
dataTest = cell(8,5);
dataTest(:,1) = cellstr(B)
% etc.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!