Conversion of a matrix into multiple column vectors
86 ビュー (過去 30 日間)
古いコメントを表示
If we have a matrix A=[1 2 ; 3 4 ; 5 6] then it will be converted to vectors like x1= [1 3 5] x2= [2 4 6]
0 件のコメント
採用された回答
Stephen23
2015 年 3 月 11 日
編集済み: Stephen23
2020 年 4 月 20 日
If you know how many columns you want, then you can simply assign them in code like this:
>> A = [1,2;3,4;5,6];
>> X1 = A(:,1);
>> X2 = A(:,2);
If you have many columns, or an unknown sized matrix, then you can split it up using num2cell with the second optional argument:
>> B = num2cell(A,1);
>> B{1}
ans =
1
3
5
>> B{2}
ans =
2
4
6
Accessing the contents of the cell array is simple and efficient using indexing:
Accessing dynamically named variables like x1, x2, x3, etc. is not recommended, because it forces you into writing slow, complex, obfuscated, buggy code that is hard to debug. Read this to know why:
5 件のコメント
Stephen23
2020 年 4 月 20 日
"is the code above correct?"
I don't know. What do you expect that code to do?
Alpha Bravo
2020 年 4 月 20 日
kindly;
- reduce m x n matrix to its frequency count
- crosstab into 2x 2
- subject those to compute chi2 and p
- interpret that result
- that is, to find the chi2, and p of the given matrix; the goodness of fit test
その他の回答 (1 件)
Giorgos Papakonstantinou
2015 年 3 月 11 日
編集済み: Giorgos Papakonstantinou
2015 年 3 月 11 日
x1 = A(:,1).';
x2 = A(:,2).';
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Performance and Memory についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!