Error using cat,cell2mat
Show older comments
% --- 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
on 13 May 2020
What are the contents of your uitable?
Walter Roberson
on 13 May 2020
Empty entries in the uitable?
Or character vectors in the uitable?
Busra Uzum
on 13 May 2020
dpb
on 13 May 2020
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.
Busra Uzum
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.
Answers (0)
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!