how can I combine two columns of an array A(m*2) in one column in the format: column1(column2)?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Joseph
am 20 Okt. 2015
Kommentiert: Joseph
am 20 Okt. 2015
i have a cell array A(m*2). the first column of consist of R and P characters and second column is just numbers. now i want put 2 columns together in the format P(number) or R(number) in which the numbers inside parenthesis are the elements of second column. can any one help with this?
thank you;
2 Kommentare
Image Analyst
am 20 Okt. 2015
I don't understand. You can't have characters and numbers in the same column vector. Please give an example.
Akzeptierte Antwort
Mohammad Abouali
am 20 Okt. 2015
So, if I understood you right you have A of size Mx2 where the first column has either the character R or P and the second column has a number. You want to have two other variables One named R and another Named P which they contain the corresponding numbers from the second column of A?
If that's what you want here is a sample code:
A={'R',1; ...
'P',5; ...
'R',3; ...
'R',10; ...
'P',6; ...
'R',8};
R=cell2mat(A(strcmpi(A(:,1),'R'),2))
R =
1
3
10
8
P=cell2mat(A(strcmpi(A(:,1),'P'),2))
P =
5
6
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!