Effacer les filtres
Effacer les filtres

Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

Grouping a given matrix into sub matrices

1 vue (au cours des 30 derniers jours)
Abin Krishnan
Abin Krishnan le 14 Fév 2014
Clôturé : MATLAB Answer Bot le 20 Août 2021
I have a matrix (1000 X 2) of two columns: first column is the time and the second column is the velocity at the respective time. The time varies from 0 seconds to 0.8 seconds and contain 1000 elements.I need to divide this matrix into several sub matrices in which the time varies by 0.1 seconds. That is, in the first sub matrix ,I need the data of velocities corresponding to time t=0 to t=0.1 seconds.Second sub matrix should contain velocities from t=0.1 to 0.2 seconds. Like that the last sub matrix contains velocities from t= 0.7 to 0.8 seconds.

Réponses (2)

Azzi Abdelmalek
Azzi Abdelmalek le 14 Fév 2014
Modifié(e) : Azzi Abdelmalek le 15 Fév 2014
t=linspace(0,0.8,1000)'
y=rand(1000,1)
idx2=[];
ii=0;
idx1=1;
t(end+1)=0.81;
for k=0.1:0.1:0.8
ii=ii+1;
idx2=find(t>k,1)-1;
out{ii,1}=[t(idx1:idx2) y(idx1:idx2)]
idx1=idx2+1
end

Jos (10584)
Jos (10584) le 14 Fév 2014
Let M be your matrix with time in the first column
[~, ix] = histc(M(:,1), 0:0.1:0.8)
C = group2cell(M(:,2),ix)
Now, e.g., C{3} contain all the values of M(:,2) for which 0.2 < M(:,1) < 0.3
  2 commentaires
Abin Krishnan
Abin Krishnan le 15 Fév 2014
it is showing undefined function group2cell for the input argument group2cell..
Jos (10584)
Jos (10584) le 15 Fév 2014
You should download GROUP2CELL from the Matlab File Exchange. It is a user-written function that is not part of of native matlab.
Download the zip-file, expand it, and move the file group2cell.m to a folder on your drive (e.g., D:\UsefulMfiles) and add that folder to the matlab path (File -> Path or something like that)

Cette question est clôturée.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by