Error using cat,cell2mat

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
linedata = get(handles.uitable1,'Data',)
linedata = str2num(cell2mat(linedata));
fb = linedata(:,1); % From bus number...
tb = linedata(:,2); % To bus number...
r = linedata(:,3); % R value
x = linedata(:,4); % X value
z=r+j*x; % Impedance
y = 1./z; % To get inverse of each element...
linedata = [fb tb r x y];
set(handles.uitable1,'Data',linedata);
This my matlab code. I got error
Error using cat
Dimensions of arrays being concatenated are not consistent.
Error in cell2mat (line 83)
m{n} = cat(1,c{:,n});
Error in termproject>pushbutton2_Callback (line 113)
linedata = str2num(cell2mat(linedata));
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in termproject (line 42)
gui_mainfcn(gui_State, varargin{:});

6 Comments

Rik
Rik on 13 May 2020
What are the contents of your uitable?
Empty entries in the uitable?
Or character vectors in the uitable?
my uitable is matrix like this
z=[0 1 0 1;
0 2 0 0.8;
1 2 0 0.4;
1 3 0 0.2;
2 3 0 0.2;
3 4 0 0.8];
Set a breakpoint on the line
linedata = str2num(cell2mat(linedata));
and then look at what linedata contains before trying to execute the line.
It will have an issue when the error occurs of something inconsistent.
Your so-called sample z data isn't even a cell array and is already numeric so doesn't at all represent the char() string data being returned by the uitable object.
first of all thanks your answer. I see, but i have no idea how can i correct it. I don't want to show z in the table anyway, I want the values I enter in the table to create z as r + j * x and calculate the resulting z with y and write them in the table.
dpb
dpb on 13 May 2020
Edited: dpb on 13 May 2020
Well, to do that you've got to write code that will handle what the uitable object returns -- part of that is that apparently now the .Data property returns a MATLAB table...I don't do GUIs so hadn't had reason to look at the doc for ages--since before the introduction of the table class.
When you get to that breakpoint as above, show us what
whos linedata
returns in the command window from the debug prompt...
With the table object, the data may already be numeric but you'll have to dereference the variables properly...dunno w/o seeing what is actually being returned what code you need here.
There are examples of writing callbacks in the doc -- there's also a difference in how the GUI is created that have to deal with to be sure you're looking at the correct examples/documentation.

Sign in to comment.

Answers (0)

Categories

Tags

Asked:

on 13 May 2020

Edited:

dpb
on 13 May 2020

Community Treasure Hunt

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

Start Hunting!