How to locate and extract elements from a matrix?
87 ビュー (過去 30 日間)
古いコメントを表示
Hi, I need to locate specific elements in each column of a matrix and print them in a new column matrix. For example if I have a 6x4 matrix
A = [a1 b1 c1 d1;
a2 b2 c2 d2;
a3 b3 c3 d3;
a4 b4 c4 d4;
a5 b5 c5 d5;
a6 b6 c6 d6]
I should locate some elements from the first column of matrix A, and print them into two new column matrices B and C. The first column of matrix A is a1, a2, a3, a4, a5, a6
My new matrix B should take these elements: a1, a2, a3, a4, so
B = [a1; a2; a3; a4]
After that I should define new matrix C, which will take elements a3, a4, a5, a6, so
C = [a3; a4; a5; a6]
This process I need to repeat for every column of matrix A. Does anyone have tips how to do this? Thanks!
4 件のコメント
Image Analyst
2015 年 12 月 18 日
You've accepted harjeet's answer so we'll assume that his code does the rules you gave above and the problem is now solved.
採用された回答
harjeet singh
2015 年 12 月 17 日
try this
clear all
close all
clc
A=randint(6,4,[1 100])
for i=1:size(A,2)
o=A(:,i);
B=o(1:4)'
C=o(3:6)'
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!