Help with arranging and creating matrices from a matrix.
1 view (last 30 days)
Show older comments
I have a matrix which a call vacia1(180x9). The number of rows will always be 180, but the number of columns will vary depending on the user of the program. The columns will grow in sets of 3 by 3. What I need for the program to do is to create new matrices from the original matrix, called vacia1, which can grow in sets of 3 by 3. An example would be: v1=vacia1(:,1:3) v2=vacia1(:,4:6) v3=vacia1(:,7:9)
This example gives the answer that I need, however I need for the program to give the new matrices without the user having to enter the indexes of what columns to obtain from matrix vacia1. After that I need to id the positions of the repeating lines (rows) in the new matrices. To solve the second problem I have this: [uniquevacia1,~,uIdx]=unique(v1,'rows') modeIdx=mode(uIdx) modeRow=uniquevacia1(modeIdx,:) whereIdx=find(uIdx==modeIdx)
[uniquevacia2,~,uIdx2]=unique(v2,'rows') modeIdx2=mode(uIdx2) modeRow2=uniquevacia2(modeIdx2,:) whereIdx2=find(uIdx2==modeIdx2)
[uniquevacia3,~,uIdx]=unique(v3,'rows')
modeIdx=mode(uIdx)
modeRow=uniquevacia3(modeIdx,:)
whereIdx3=find(uIdx==modeIdx)
This will give the rows that repeat in the original matrix (vacia1). But I do not know how to tell MathLab to do all of this for Vn matrices.
Thanks in advance!!!
0 Comments
Accepted Answer
Stephen23
on 11 Sep 2014
Edited: Stephen23
on 11 Sep 2014
Do NOT create new variables dynamically like this in MATLAB: it is topic that has been discussed many times before:
The best solution is to not split your array. Keep it as one data array, and access the required parts of it by indexing. This is faster, less prone to buggy code, and produces less clutter in your workspace.
0 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!