separating numbers in cells
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Berfin Çetinkaya
am 19 Mai 2022
Kommentiert: Berfin Çetinkaya
am 19 Mai 2022
I have a matrices like :
1-8 7-1 8-4
4-6 8-5 7-3
I want to separate it as two matrices.
first matrix :
1 7 8
4 8 7
second matrix:
8 1 4
6 5 3
How can I do that?
Thank you
0 Kommentare
Akzeptierte Antwort
Stephen23
am 19 Mai 2022
Assuming that you have a cell array of character vectors:
C = {'1-8','7-1','8-4';'4-6','8-5','7-3'}
D = split(C,'-');
A = str2double(D(:,:,1))
B = str2double(D(:,:,2))
Weitere Antworten (1)
David Hill
am 19 Mai 2022
Do you mean a cell array like this?
a={'1-8','7-1','8-4';'4-6','8-5','7-3'};
m=zeros(size(a));n=zeros(size(a));
for k=1:numel(a)
m(k)=str2double(a{k}(1));
n(k)=str2double(a{k}(3));
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Types 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!