[英]How to split cell array values into two columns in MATLAB?
我在單元格數組中有數據,如此處的變量查看器所示 :
{[2.13949546690144;56.9515770543056],
[1.98550875192835;50.4110852121618],
...}
我想將其分為兩列,兩個小數點為:
2.13 56.95
1.98 50.41
通過刪除大括號和分號(例如[;]
(類似於Excel中的“文本到列”)。
% let's build a matching example...
c = cell(2,1);
c{1} = [2.13949546690144; 56.9515770543056];
c{2} = [1.98550875192835; 50.4110852121618];
% convert your cell array to a double array...
m = cell2mat(c);
% take the odd rows and place them to the left
% take the even rows and place them to the right
m = [m(1:2:end,:) m(2:2:end,:)];
% round the whole matrix to two decimal digits
m = round(m,2);
根據您的環境設置,您可能仍會在前兩位十進制數字后看到很多結尾的零...但不要擔心,一切都很好(從精度角度來看)。 如果只想顯示數字的“實數”數字,請使用以下命令:
format short g;
你應該使用cell2mat
A={2.14,1.99;56.95,50.41};
B=cell2mat(A);
關於四舍五入,您可以執行以下操作:
B=round(100*B)/100;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.