Why do I get the error Cell contents reference from a non-cell array object. Below is my code. Can anybody tell me what is wrong with this code?
%Read data from database.
curs = exec(conn, sprintf(['SELECT description.imageName'...
' , description.brand'...
' , description.price'...
' , description.size'...
' , description.clothingDescription'...
' FROM description WHERE description.imageID ="%s"'],imagename));
curs = fetch(curs);
close(curs);
%Assign data to output variable
results = curs.Data;
disp(results);
set(handles.edit1,'String',results{1});
set(handles.edit2,'String',results{2});
set(handles.edit3,'String',results{3});
set(handles.edit4,'String',results{4});
set(handles.edit5,'String',results{5});
This is the full error message
Cell contents reference from a non-cell array object.
Error in image_desc1>image_desc1_OpeningFcn (line 90)
set(handles.edit1,'String',results{1});
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in image_desc1 (line 42)
gui_mainfcn(gui_State, varargin{:});
This is one of the sample data execute in command window when typing the code in
WHERE description.imageID =1
'High Neck Tee' 'ZALORA' [40] 'S,M,L,XL' 'Blush High Neck by ZALORA'
After typing the whos, it show this sentence in command window
Name Size Bytes Class Attributes
results 1x1 8 double
The error communicates the message clearly as it is. The variable results is not a cell array and you are trying to extract non-existing results{1},...,results{5}. Hence the error.
Related
I have a question and I'd appreciate some help.
temp = importdata('teste.txt');
for i= 1:size(temp.texdata,1)
for j= 1:size(temp.texdata,2)
if i== 1 || j <= 2 %copy alphanumeric data of 1º row and columns 1 and 2
dados{i,j} = temp.texdata{i,j};
elseif j-2<= size(temp.data,2) %copy numeric data for the remain cells
dados{i,j} = temp.data(i-1,j-2);
end
end
end
error: matrix cannot be indexed with .
error: parse error
error: called from
C:/......../1º Semestre/IP/projeto_2.0.m at line 134 column 1
It appears the error on top cause I wrote on my code.
My code must import data from a very big txt file that I have.
Do you have any suggestions on how to solve the problem
When you import the data, temp is a matrix, not a struct.
Attempting to access a field as if it where a struct results in the error you observe
I wrote a function, wins_plot, to read the scoreboard from a file and store the player's name, number of plays, wins, & losses. I stored all those using struct. I loop over the file, store each line in line, textscan for everything I need from line, and then iterate i (initially == 1) as I go to expand my array of structures. A snippet from the code to represent what I am saying:
c = textscan(line, '%s %s %d %d %d');
player(i).firstName = c{1};
player(i).lastName = c{2};
player(i).plays = c{3};
player(i).wins = c{4};
player(i).losses = c{5};
After all the file has been scanned and stored, I then write this code to extract the number of wins of each player and store it in X and then finally use the pie function to represent the values in X
for n=1:(i-1)
X(n) = player(n).wins;
end
pie(X);
I get a wall of error after:
Undefined function 'cos' for input arguments of type 'int32'.
Error in pol2cart (line 22) x = r.*cos(th);
Error in pie (line 99)
[xtext,ytext] = pol2cart(theta0 + x(i)*pi,1.2);
Error in wins_plot (line 30) pie(X);
I have no clue what might be wrong. Any help would be greatly appreciated. Please keep in mind that I only just started learning MATLAB today so my knowledge of it is very limited (and I have R2013a). Thank you in advance!
The numbers got read as int32, but when you call pie, it requires them to be double to do the computation. So, when you call pie, try casting the values to double. Try this,
pie(double(X));
I have matrix 3x108 which contains dimension data. I want to find min and max value of my matriks in each row. Here's my code:
P = load('grading/dimension.mat');
min_P = min(P,[],3);
max_P = max(P,[],3);
but it gives me error:
??? Error while evaluating uicontrol Callback
??? Undefined function or method 'min' for input arguments
of type 'struct'.
Error in ==> guikedelaizulfa>identifikasi_Callback at 1427
min_P = min(P,[],3);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> guikedelaizulfa at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
#(hObject,eventdata)guikedelaizulfa('identifikasi_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
Can you help me? Thanks
Using P=load(...) the function returns a single struct which contains all variables. Assuming you have used the variable name X when saving, you can access the variable using P.X. I recommend to set a breakpoint and take a look at the loaded data using the Variable Explorer or the fieldnames function.
I have been trying to open files in a loop. I did this:
file='';
loc='F:\UT_timestep\';
name='time_';
gridext='.grd';
for i={'a','b','c'}
file=strcat(loc,name,i,gridext);
f=fopen(file,'rb');
...
fclose(f);
end
but it gives this error :
Error using fopen
First input must be a file name of type char, or a file identifier of type double.
Error in script_UT (line 28)
f=fopen(file,'rb');
I am not able to understand why this is giving error. Please help.
This is because file is a cell array of 1 element. You want the actual string inside the cell array, not the actual cell itself. Do this:
file='';
loc='F:\UT_timestep\';
name='time_';
gridext='.grd';
for i={'a','b','c'}
file=strcat(loc,name,i,gridext);
f=fopen(file{1},'rb'); %// Change
...
fclose(f);
end
i'm completely new to matlab and this is my first question.
I found a program like this
x = inputdlg('foo');
x = str2num(x{1})
and trying to make some gui from it, put this line to callback function of push button:
x=get(handles.edit1, 'String')
x=str2num(x{1})
and it works, but not after i add this the same thing with different variable
y=get(handles.edit2, 'String')
y=str2num(y{1})
command window said
Cell contents reference from a non-cell array object.
Error in regresilinear>pushbutton1_Callback (line 128)
x=str2num(x{1})
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in regresilinear (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
#(hObject,eventdata)regresilinear('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
I found out that the output from command window is different when it's running and not with the same input.
When it got errors:
x =
0 1 2 3
when not (the first time)
x =
'0 1 2 3'
It doesn't give any error if i delete the str2num line.
I hope somebody can help fix the problem.
Start with a clear workspace and
x=get(handles.edit1, 'String');
x=str2num(x);
or better:
x=str2num(get(handles.edit1, 'String'));
{} are used for accessing the elements of a cell array. You are probably trying to use it on a string and that is why you are getting that error.