what can i do to solve this error in my program(learning the net)? it appear after sim. the net.
Error in ==> network.sim>simargs at 236
switch class(P)
??? Output argument "Pi" (and maybe others) not assigned during call to "C:\Program
Files\MATLAB\R2008b\toolbox\nnet\nnet\#network\sim.m>simargs".
Error in ==> network.sim at 173
case 2, [err,X,Xi,Ai,T,Q,TS,matrixForm] = simargs(net,X);
Error in ==> mlptrptest at 62
y = sim(net,A{1,1})
Note: Don't fall into the same trap I did. There is also a function called SIM in Simulink that will likely show up in searches for the function SIM in the Neural Network Toolbox...
The first thing I would check is that the second input argument A{1,1} is of the correct form. Specifically, A{1,1} would have to be a cell array or a matrix of doubles. If it is of any other form, like a structure or a matrix of any other class, you will get the error you are seeing. Admittedly, this particular error isn't handled very well by the subfunction simargs, in that it gives you some cryptic messages that don't really tell you the basic problem, which is that your input is not in the right format.
Here are a couple things to check:
Do you really mean to pass the first element of cell array A as an input argument, or do you mean to simply pass the cell array itself? If it's the second option, just do this:
y = sim(net,A);
If you do mean to pass the first element of A as an input argument, double-check it's class using the function CLASS:
class(A{1,1})
If you don't see double displayed, it means the first element of A is not the right type. If it is a matrix, you can convert it to double before you pass it to SIM like so:
y = sim(net,double(A{1,1}));
Related
I have a struct as shown in picture, and I need to address one of the columns in a FOR loop, as shown. But I keep getting this error:
Function 'subsindex' is not defined for values of class 'struct'.
Error in analisa_arx_teste (line 351)
In my case, what i want is :line 1 represents i = 1, line 2 i =2; So, for features, When I ask for pref_estemod(i).features is to get the values from the field features associated to each model.
I am just starting programming with matlab, so all your help would be appreciated.
Thanks!
for i=pref_estemod(1:npreferred)
[m,n]=size(Training);
features=(pref_estemod(1,i).features);
end
The error lies in i=pref_estemod(1:npreferred).
If you intend to use i for indexing, the syntax is for i=1:npreferred.
1:npreferred itself expands to the horizontal array [1,2,...,npreferred]. = with a leading for is a special syntax combination. It means do the following code with i=1, i=2, ..., i=npreferred. Now I am sure you already know the idea behind for loop. The reason I write all this is to give you the following warning/advise. Do NOT expect the same syntax to work with non-numeric arrays. Because it works in some cases and not others.
I want to create input dialog box in matlab. I am performing simple addition operation in MATLAB.
Two variables name, a and b are needed to be given by user and then performing addition c=a+b; and display it in output. Both a and b should be positive integer only.
I tried following:
a = inputdlg({'Enter positive integer (a)'});
b = inputdlg({'Enter positive integer (b)'});
c=a+b;
But it is giving following error:
Undefined function or method 'plus' for input arguments of type
'cell'.
Please suggest how can i code the above program in described way.
That's because the output of inputdlg is a cell array containing a string; here a 1-cell array.
Hence you need to access the content of the cell array to perform the operation; for example using {curly brackets} : {a} and {b}.
In your case, since you are asking the use for a number, you need to convert the output, which is a string, to an actual number Matlab can use using for instance str2double, which operates on cell arrays
c = str2double(a) + str2double(b)
Suppose I have a function that gives out unknown number of output arguments (it depends on input,thus change through the loops). How to get all of them?
nargout doesn't help as the function uses varargout (the result is -1)
And of course I can't rewrite the function, otherwise the question wouldn't arise :- )
Well, thanks to all partisipated in discussion. Summing up, it seems the problem has no general solution, because MatLab itself estimates the number of desired outputs before the function call to use inside it. Three cases can be pointed out though:
1) The funcrion doesn't have varargout in definition, thus nOut=nargout(#fcn) returns positive number.
Then nOut is an actual number of outputs and we can use a cell array and a column list trick.
X=cell(1,nOut);
[X{:}]=fcn(inputs);
2) The funcrion has varargout in definition, thus nOut=nargout(#fcn) returns negative number. However some correlation with inputs can be found (like length(varargin)=length(varargout)).
Then we can calculate the resulting nOut from inputs and perform the above column list trick.
3) You know the fcn developer.
Ask him fot assistance. For example to make the function's output to be a cell array.
One of ways I usually use in this case is to store all outputs in a cell array inside the function. Getting the cell array outside the function's body, you might investigate its length and other properties.
Here is how you could deal with the problem in general. I didn't mention this solution earlier because... it is horrible.
Suppose a function can have 1 or 2 output arguments:
try
[a, b] = f(x)
catch
a = f(x)
end
Of course it is possible to do this for any number of output arguments, but you really don't want to.
I am running a GUI system in MATLAB and I am a beginner with working with GUI's.
The code is extensively long and so I am going to just put in what and where I have things and see if it is enough information for help to be given, thanks.
in my first GUi I have this in the opening function:
HW12_result_bhanford(handles.scan_age, handles.check_athlete, handles.radio_male, handles.radio_female)
this is supposed to be transferring these four variables over to my third GUI named
HW12_result_bhanford
In my second GUI I have this written in the opening function:
age = varargin{1}
athlete = varargin{2}
male = varargin{3}
female = varargin{4}
I then use these four variables(age, athlete, male, female) later in the second GUI and I
assume them to be the equivalent value of the corresponding variable passed from the first
GUI.
When I run everything the error that comes back is Index exceeds matrix dimensions.
if anyone could help me, that would be awesome. If you cannot help without the entire code I understand.
You use varargin if your argument list is variable, and varargin has to be in your function definition.
function HW12_result_bhanford(varargin)
In this case function receive a cell array as an input, so you can get individual arguments with varargin{1} etc.
If you put your arguments together as a structure, you can pass this structure as an argument along.
function HW12_result_bhanford(handles)
But if the function definition has individual arguments, for example,
function HW12_result_bhanford(age, athlete, male, female)
you cannot use varargin, just process the arguments as is.
Read more on how to use VARARGIN.
I am trying to find log of base 10 of each pixel of an image in matlab using following code
m1 = imread('owl','pgm');
for x = 1:size(m1,1)
for y = 1:size(m1,2)
m1(x,y) = log10(m1(x,y));
end
end
here m1 is a 2-D array of order 221 X 201.
but I am facing this error
??? Undefined function or method 'log2' for input arguments of type 'uint8'.
Error in ==> log10 at 20
y = log2(x);
Error in ==> q2 at 38
m1(x,y) = log10(m1(x,y));
but when I debug log function using following code
fprintf('log of 190 is %d', log10(190));
it gives me right output I dont know what happened when I use the same code in the loop.
The error message tells you what the problem is, you've tried to apply the log10 function to a value of type uint8 and the function is not defined for that type of number. What you haven't realised is that imread, when an image file meets certain criteria (read the documentation for what those criteria are) will capture the pixel data into an array of uint8s, not real numbers.
If you want to take the logarithm of a uint8 you'll either have to define a logarithm function of your own which takes such inputs, or, more straightforward, cast the uint8 to a type which log10 is happy with. For example, you could write:
log10(double(m1(x,y)))
And by now you'll have realised why your diagnostic test didn't tell you anything useful, when you execute the command log10(190) Matlab, by default, decides that 190 is of type double and computes the logarithm without complaint. log10(uint8(190)) tells a different story.