I am still new in using MATLAB. I am trying to create a feed-forward neural network with MATLAB custom function feedforwardnet, I got my own training set with dimension 2 x 100, which is a multiple-input array.
Now I ran into the problem of how to feed this array into the feedforwardnet function. I tried
[NNINputs, NNTargets] = [n_xk, target] ;
where both n_xk and target are 2 x 100 "double" arrays. It shows the error:
??? Too many output arguments.
I also tried wrapping the array into a cell array as follows
myTrainSet = num2cell([n_xk, target]) ;
This time, it shows
??? Undefined function or method 'feedforwardnet' for input arguments of type 'double'.
But how? the neural network runs like a charm with the default dataset
load house_dataset ;
which is also a 13 x 251 arrays both its input and output. How come it can't work with my cell array or numeric matrix? I've searched through the internet and no much literature covers this topic, and if it does, the discussion is still unclear. Thanks for the help in advance!
Related
i'm sorry, maybe is a stupid question, but i have issue to set my array variable in a stateflow chart by using C Action Language.
Usually in c language i can put in my static array all the values with " A[]={1,3,2}; " , but in stateflow chart, with C ActionLanguage how i can it? (in matlab language work, but i need in C)
I've defined my variable with output scope (becouse it is), setted the size as 3 (i want an array of 3 elements), set First index as "0" and type int8.
If a want in output the array "1,2,3" i write " gates=[1,2,3]; " , i've tried also "gates=[1 2 3]", etc, but i receive syntax error.
What are my errors?
i've read in this link: https://it.mathworks.com/help/stateflow/ug/operations-for-vectors-and-matrices.html
Assign Values to All Elements of a Matrix In charts that use MATLAB as
the action language, you can use a single action to specify all of the
elements of a vector or matrix. For example, this action assigns each
element of the 2-by-3 matrix A to a different value: A = [1 2 3; 4 5
6]; In charts that use C as the action language, you can use scalar
expansion to set all of the elements of a vector or matrix to the same
value. Scalar expansion converts scalar data to match the dimensions
of vector or matrix data. For example, this action sets all of the
elements of the matrix A to 10 A=10;
but not explain how set different values in all the array, and also i need that the output from the stateflow chart is in a single step :(.
in the image there is a step with a syntax error. Someone can explain me how i can solve?
Stateflow chart screenshot
thankyou!
Well, there are 2 ways I would do it:
Define the values for ex: g1 = [1 0 0]; g0 = [0,0,0] in MATLAB workspace. And then in your stateflow use the values like gates = ml.g1; This works with C action language.(attached image gives a preview of this method)
Implement a for loop(maybe a graphical function or a MATLAB function) inside your chart, which is used to assign values to your output array.
Of the two, I think the first method is easier to deal with, if the no of values the variable 'gates' takes is limited. Else, go for method 2.
I want to resample an array of elements using the command idresamp(). The input arguments for idresamp function is an array x. So I should get the output as an array. However, I am getting a structure iddata. I don't know how to access the elements /result of the resampling. Can somebody please show how to access the resampled values? Thank you.
x=rand(4000,1); %create some arbitrary data
x_resamp =idresamp(x,2); %resampling factor is 2
Here x_resamp is of iddata type. So, I am unable to access the result. On clicking the variable x_resamp this is what I got
How does one access the resampled values (output). Where is the array? The next step is to calculate the power after resampling and hence I need to use the resampled values.
I am using Matlab R2018a.
If you just want to resample by a factor 2, and have access to the Signal Processing Toolbox, use resample:
y = resample(x,2,1);
If you are insistent on using idresamp, you need to know that it returns an object of type iddata, which comes with a long documentation on usage. I think this complicates things more than you are looking for. It seems you should be able to do:
x_resamp = idresamp(x,2);
y = x_resamp.OutputData;
(but I can't test this because I don't have access to this toolbox.)
I have two 1D arrays that gives an array of points on the XY plane. What I am trying to achieve is to find that steps interpolation for which values is exactly 0.5. I've tried to solve it using Interpolate 1D array and Threshold 1D array but no success. The first only returns values information for which steps == 0.5 and the latter is not doing anything apparently, returning 0 always.
I've attached the front panel and block diagram to the post. On the front panel I indicated which information I need.
Could you please help me figure out what I am doing wrong here? Because I'm quite stuck with this. Thank you in advance.
Kudos for solving it yourself, but a vi post of the solution would be appreciated for further reference by other people. Here is a solution that uses the 1D interpolation from the mathematics section. One VI, only downside is that you need to convert you interpolation value to an array and the answer back.
I managed to solve it. Threshold 1D array vi cannot deal with arrays that contain decreasing values... a rather frustrating error, as I need to transform the array so that the characteristics become increasing to obtain the interpolated value.
From the documentation:
Note Use this function only with arrays sorted in non-descending
order.
I have a cell array thiscells:
thiscells <1*40 cell>
eacharray of thiscells is 280*3
I have a function (TheFunction) that gets input of cell array that each array is X*2
How can I send a cell array to TheFunction that contain only columns1,3 from each array?
I tried
TheFunction(thiscells{:}(:,1:2)) % tring to send only columns 1,2
But it didn't work
Edit:
working with (but still looking for faster way to do so):
What is did so far
TheFunction(makingNewCells(thiscells,2));
when
makingNewCells:
[newCells]=makingNewCells(oldCells)
for ii=1:max(size(oldcells))
newCells=oldCells(:,[1 column]);
end
This question and its answers may be of help - thiscells{:}(:,1:2) is already failing without the call to Thefunction, if I am not mistaken.
For cells, the problem is even worse: add to this impossibility to double-subref that even if it did what you intended it to do, this passes 40 arguments (which are all 280x2 vectors) to Thefunction. I doubt there are (m)any legitimate uses for a function that takes 40 arguments of the same type, instead of having those wrapped in a cell. I would probably try doc cellfun first.
EDIT: just to be clear, I suggest changing Thefunction so that it accepts a cell of 40 matrices of size 280x2), then using
cell_of_twocolumned_arrays = cellfun(#(x)x(:,[1 2]),thiscells)
I have a problem with realtime video processing in Matlab for gesture recognition. I have tried
n = 20; % 'n' is the number of frames i want to capture
%preallocating frame()
for i=1:n
frame(:,:,:,i) = getsnapshot(vid);
end
But when I try to access each array using the following loop
for i=1:n
image=frame(:,:,:,i);
y=imresize(image,[50, 50]);
b=rgb2gray(y);
%%processing for features
end
the array b always contains the value 1. Is there anything wrong with my implementation? Do I always have to convert each frame into an image file?
The problem is most likely in the only code snippet you haven't provided :P
When you preallocate the frame array make sure it's something like:
frame = zeros(720,1280,3,N,'uint8');
Only calling zeros() with no cast will allocate it as an array of doubles. It seems that using 'int8' also gives unwanted results. Maybe this is different on your machine.