How can I splitt up a big matrix into smaller matrises, splitting it up by values on the x-axis
7 ビュー (過去 30 日間)
古いコメントを表示
I have a large matrix that should be divided into smaller matrices based on the value in the x-axis. The large matrix, 100X3, has values where the columns represent the x, y and z-axis.
The large matrix should be divided into 10 smaller matrices, the first one containing values x<50, the next one x-values from 50-59, next one 60-69 and so on .
There is no correlation in how many rows there are of each x-value, which can make the first matrix a 50x3 matrix and the next one a 7x3 matrix.
It all have to be done using for loop, and hopfully be made in a way that makes it easy to change, both the number of matrices and the value they are ranging between.
I have figured out how i can divide it into smaller matrices, but just by dividing it into equal parts.
Actually i work with a huge point cloud of a bridge and it have to be divided into smaller segments so that it is easier to work with.
I hope someone can help me..
4 件のコメント
Adam Danz
2020 年 2 月 17 日
Are the x-axis values the values in column 1 of the matrix or are they the row-number of matrix?
採用された回答
Joseph Cheng
2020 年 2 月 18 日
編集済み: Joseph Cheng
2020 年 2 月 18 日
so the main question is whether the ranges for the smaller matrixes are known or need to be detectable. then you can use a for loop to break them into smaller matrixes
%gen dummy data
A(:,1)=1:100;
A(:,2:3)=randi(100,100,2);
%designate start and stop ranges for x
xRngstart=[1 50 60 70 80 90 100]
xRngstop =[xRngstart(2:end)-1 xRngstart(end)];
%loop through each start index and save it in a structure
for ind = 1:numel(xRngstart)
Processed(ind).SmallerM = A(xRngstart(ind):xRngstop(ind),:);
end
or if x is not really integers you can do the same thing with ranges checks
%gen dummy data
A(:,1)=0:100;
A(:,2:3)=randi(100,numel(A(:,1)),2);
%basically the ranges of the smaller blocks are designated by being between n and n+1
xRngs=[min(A(:,1)) 50 60 70 80 90 100 max(A(:,1))]
for ind = 1:numel(xRngs)-1
rows = A(:,1)>=xRngs(ind) & A(:,1)<xRngs(ind+1); %check to see which rows of A are between
%xRng(ind) and xRng(ind+1)
Processed(ind).SmallerM = A(rows,:);
end
その他の回答 (1 件)
Jakob B. Nielsen
2020 年 2 月 18 日
編集済み: Jakob B. Nielsen
2020 年 2 月 18 日
Logical indexing will help you here - a for loop is also possible but would be much more complicated.
Lets call your initial matrix X.
A=X(X(:,1)<50,:);
This places into A all values of X, where the condition in column 1 meets the requirement - here less than 50 - that you specify. When there are multiple conditions, an & sign means logic AND (takes the value if and only if both conditions are true), and a | sign means logic OR (takes the value if one or the other or both are true).
B=X(X(:,1)>=50 & X(:,1)<60,:); %greater than or equal 50, but less than 60.
Of course, remember that if you put less than 50 as the first condition, then the next condition must be greater or equal to 50; if you only put greater than 50, you will miss out all values which are exactly 50.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!