Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Matlab Programming.Help!!!

Status
Not open for further replies.

Nikolas83

Junior Member level 2
Joined
Oct 17, 2006
Messages
20
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,411
Hello once again…
:DI am doing an exercise in matlab programming and I wondered if somebody of you could me help..
I want the matrices that I have in my problem to put them in a line(array)..
for example I have matrices A=[2 4; 5 6 ] and B=[4 6 7;6 3 4 ]
and i want to put the elements of matrices in one array..
to do this think r=[2 4 5 6 4 6 7 6 3 4]..
I do some thinks but..i did not find anything good..
 

Try this:
A = [2 4; 5 6];
B = [4 6 7; 6 3 4];
r = [reshape(A',1,[]) reshape(B',1,[])];
 

    Nikolas83

    Points: 2
    Helpful Answer Positive Rating
echo47 said:
Try this:
A = [2 4; 5 6];
B = [4 6 7; 6 3 4];
r = [reshape(A',1,[]) reshape(B',1,[])];

echo47 Thanks a lot..my friend...
i think its match in my exercise.
 

Hello..Again
I think that my problem isnt solve yet..
Because the matrices have the form below...

A = zeros(2,2,3);
B = zeros(2,1,3);
A:),:,1) =eye(2);
A:),:,2) = [-1.5 0.1;-0.2 1.5];
A:),:,3) = [0.7 -0.3;0.1 0.7];
B:),:,2) = [1;-1];
B:),:,3) = [0.5;1.2];

and if i try to run with the 'reshape' commant..
It saw to mee the below error..:cry:

Error using ==> ctranspose
Transpose on ND array is not defined.

if anyone has an idea..pleasantly i accept it..
:D
Thank you.
----------
Just found it..
the form command in mine case is
r = [reshape(A:),:,1)',1,[]) reshape(A:),:,2)',1,[]) reshape(A:),:,3)',1,[]) reshape(B:),:,2)',1,[]) reshape(B:),:,3)',1,[])]

I write because maybe that is useful for another friend with the same request..
 

do that after u Defined matrix A & B


c =[A( : ) B ( : ) ]
c = c'
 

Hi,
You can solve your problem by create a function to reshape your matrix to the form you need and then you concatenate them in the way you wnat, her is the Code of the function...
Code:
function x = change_matrix(a)
B = a;
Bx = [];
siz = size(B);
for i = 1 : siz(1)
    Bx = [Bx B(i,:)];
end
x = Bx;
And then you can call this function from the Command Window or from your M-file to perform your operation as follow, you fist have to define your matrices

>> A = [2 4; 5 6 ];
>> B = [4 6 7;6 3 4 ];
>> C = [change_matrix(A) change_matrix(B)];

then matrix C will equal..
C = [2 4 5 6 4 6 7 6 3 4];
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top