What you are trying to do is create a comma-separated list from a numeric vector. As far as I know, there is no inbuilt way to achieve this. This question has also been asked before , you might find other discussions on this online. Usually in MATLAB it makes a lot more sense to keep your data together in arrays, so it may not be necessary to do this multiple-assignment. You should consider this. However if it really is necessary to do this multiple assignment, then you could:
- Assign individually: n = A(1,1); m = A(1,2);
- Assign via a cell array:
B = num2cell(A(1,1:2));
[n,m] = B{:};
Although the first option is much clearer!
EDIT: on re-reading your question, it seems that perhaps all you are after is just the vector of the first row of A, in which case you do not need to assign to two separate values first, as you can just extract the vector directly:
If you just need the row (vector), then there is no need in MATLAB to create intermediate variables m,n.
1 件のコメント
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/175231-extract-first-row-from-matrix#comment_442719
このコメントへの直接リンク
https://jp.mathworks.com/matlabcentral/answers/175231-extract-first-row-from-matrix#comment_442719
サインインしてコメントする。