How to save the Data in different array using Value in 2nd column
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
3 comentarios
Arif Hoq
el 24 de En. de 2023
do you want only for 15,37,25 ?? or do you need all the unique values of column 2?
Jan
el 24 de En. de 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.
Thank you.
Respuestas (1)
Stephen23
el 24 de En. de 2023
Editada: Stephen23
el 24 de En. de 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:
0 comentarios
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!