1 view (last 30 days)

function A=combined (V)

for V(k)= A(i,j)

k=1;

for

i=1;

j=1;

k=k+1;

end

end

dpb
on 27 Sep 2016

"...transform my matrix into a vector"

Really don't need a function for this; Matlab has syntax to do it already. A previous answer shows reshape, except I'd suggest to simply use it ( reshape, that is) inline as shown there in the function instead.

There's another Matlab idiom that's even more compact--

A=A(:).'; % convert A of unspecified dimensions to row vector

NB: the .' transpose operator to return the requested row vector instead of the column vector colon returns.

dpb
on 27 Sep 2016

James Tursa
on 28 Sep 2016

Here is an outline of what you need to be using for the for loops (seems to be a requirement for this assignment).

% Insert any initialization code here

for i = 1:size(V,1)

for j = 1:size(V,2)

% Insert your assignment etc code here

end

end

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

Start Hunting!
## 3 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/304749-i-am-trying-to-create-a-function-form-a-vector-from-my-matrix-and-i-do-not-understand-where-my-mista#comment_394157

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/304749-i-am-trying-to-create-a-function-form-a-vector-from-my-matrix-and-i-do-not-understand-where-my-mista#comment_394157

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/304749-i-am-trying-to-create-a-function-form-a-vector-from-my-matrix-and-i-do-not-understand-where-my-mista#comment_394160

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/304749-i-am-trying-to-create-a-function-form-a-vector-from-my-matrix-and-i-do-not-understand-where-my-mista#comment_394160

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/304749-i-am-trying-to-create-a-function-form-a-vector-from-my-matrix-and-i-do-not-understand-where-my-mista#comment_394239

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/304749-i-am-trying-to-create-a-function-form-a-vector-from-my-matrix-and-i-do-not-understand-where-my-mista#comment_394239

Sign in to comment.