How to save the Data in different array using Value in 2nd column
8 views (last 30 days)
Show older comments
Med Future on 24 Jan 2023
Commented: Jan on 24 Jan 2023
Hello, I hope you are doing well. I have the dataset which have five columns
My second columns consists the values 15,37,25 etc
I want to to save data in different array for example if i have value of 15 in 2nd column, i want to save the values of remaining four columns which correspond to 15 in different array.
Similar method for other values too.
How can i do that in MATLAB
Jan on 24 Jan 2023
@Med Future: Please do not address specific users in a question, if they are not involved in the discussion before. Imagine what would happen, if all users try to catch the attraction of some users: They will be overwhelmed by a pile of messages and will disable the notifications to stop the noise.
The most active members of this forum will post an answer if they find some time and know an answer. Pushing them by notifications will reduce their time to read questions only.
Stephen23 on 24 Jan 2023
Edited: Stephen23 on 24 Jan 2023
Clearly creating lots of separate variables in the workspace would be a very bad approach:
So instead we will use the more efficient approach of storing the split data in one cell array:
S = load('DatasetValues.mat')
M = S.DatasetValues
[U,~,X] = unique(M(:,2));
F = @(n) M(X==n,:);
C = arrayfun(F,U, 'uni',0)
Each cell of C collects the value given in the corresponding location of U.
Although splitting data up is popular with beginners, in general data should be kept together as much as possible. The split-apply-combine workflow might be useful for you, and is supported by a number of functions:
Find more on Matrix Indexing 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!