reallocating matrix concatenated as string
1 次查看(过去 30 天)
显示 更早的评论
birlestirbirincifaz = cell(20,69) ;
for i = 1:20
for j = 1:69
birlestirbirincifaz{i,j} = [num2str(sonucmatrisi(i,j)),'-',num2str(faz1atananmakineler(i,j))] ;
end
end
I combined two matrices as strings using this code.
But now I have to take it apart again. What should I do?
(small snippet of my matrix)
'10-10' '22-22' '42-42'
'193.92-8' '68.8-7' '9.34-1'
'193.92-8' '68.8-8' '9.34-3'
0 个评论
采纳的回答
Stephen23
2022-3-24
编辑:Stephen23
2022-3-24
Much better to use string arrays:
M1 = [10,22,42;193.92,68.8,9.34;193.92,68.8,9.34]
M2 = [10,22,42;8,7,1;8,7,1]
S = M1+"-"+M2
T = split(S,'-')
str2double(T(:,:,1))
str2double(T(:,:,2))
2 个评论
Steven Lord
2022-3-24
With a string array containing the text representations of numbers you don't need to use str2double. Just calling double is sufficient.
M1 = [10,22,42;193.92,68.8,9.34;193.92,68.8,9.34];
M2 = [10,22,42;8,7,1;8,7,1];
S = M1+"-"+M2;
T = split(S,'-');
M1After = double(T(:,:,1))
M2After = double(T(:,:,2))
更多回答(1 个)
Riccardo Scorretti
2022-3-24
If I understand well your question, you wish to do this:
sonucmatrisi = zeros(20, 69);
faz1atananmakineler = zeros(20, 69);
for i = 1:20
for j = 1:69
tmp = sscanf(birlestirbirincifaz{i,j}, '%f-%f');
sonucmatrisi(i,j) = tmp(1);
faz1atananmakineler(i,j) = tmp(2);
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!