Effacer les filtres
Effacer les filtres

multiple selection of parts of different size matrices

2 vues (au cours des 30 derniers jours)
Brasco , D.
Brasco , D. le 2 Fév 2015
Commenté : Guillaume le 2 Fév 2015
Hi guys i have having trouble about selecting certain parts of matrices. Here is my problem.
Let say i have two time matrices.
t1=0:1:100 and t2=0:.1:100
I want to pick certain multiple parts of t1 and then find the related zones in t2. (t1 is related to force data. and t2 is related to distance )(mass spring system)
let say i have a sinusoidal changing force matrices in 100 secs, which is time t1. and i can measure the distance more precise in time t2.
I can find the the related time for certain amount of forces, which is some parts of t1.
let say, for my force(F) is between 10 and 15 newtons and the related t1 columns ara 20 to 30, 60 to 70.
i need to find the related time columns on t2 so i can find the related dispalcements (X).
I worked on different forces (my force can change 5 to 10, 20 to 30,..) so the columns of related t1 is changing and t2 too.
anyone help me?

Réponses (1)

Guillaume
Guillaume le 2 Fév 2015
Sounds like you need intersect:
t1 = 0:1:100;
t2 = 0:0.1:100;
[commonvalues, it1, it2] = intersect(t1, t2)
%commonvalues are the times common to both
%it1 are the indices of these values in it1
%it2 are the indices of these values in it2
  4 commentaires
Brasco , D.
Brasco , D. le 2 Fév 2015
Modifié(e) : Brasco , D. le 2 Fév 2015
there are four matrices. F , t1, X, t2
F:force, length(F)=101
t1:time (1 hz ) t1=0:1:100 (100 seconds) {length(t1)=101} same as F
X= dispalcement length(X)=1001
t2= time (10 hz) t2=0:0.1:100 (100seconds) { length(t2)=1001} same as X
we know F,t1 and X,t2
Let say i am looking for F>=18:
F=[... 18 20 16 ...20 19 .. 20 19 25.. ]
t1=[...(12 13 14) .. (30 31) .. (45 46 47).. ]
I want to learn the column number of related time in t2.
t2=[... (12.0 12.1 12.2...14) ... (30.0 30.1 ..31) ... (45.0 45.1 ...47)... ]
i need to know which columns of t2 represents the time interval (12:0.1:14) and (30:0.1:31) and (45:0.1:47).
the answer shoul give me colums of t2 like:
for t1 = 12:14 columns t2 are 121 to 141
t1=30:31 columns t2 are 301 to 311 (something like that)
so i can find the related X (displacement values) using the time matrice which is stored as t2.
to sum up,
step 1: find time zones for the desired force. (for F>=18 t1=?) this helps me to find the time intervals.
step 2: let say my t1 times are 5 to 10, 20 to 30 seconds. (2 time zones 5-10seconds and 20-30seconds)
step3: now i know the time intervals(5-10 and 20-30 seconds), so i need to know related columns in t2. So using the column numbers, i can find the X values.
the trick in here is that in t1 , the time interval is simple..
t1=[. . . . (5 6 7 8 9 10) ....(30 31) .. ] but in t2 it is:
t2=[... (5 5.1 5.2 5.3...10)....(30 30.1 30.2....31)... ]
so the column numbers in t1 are like 5,6,..,10 and 30,31 but t2 is more than that. column numbers in t2 may like 50,51,52,53....,150 and 300,301,302,..,310
i need to know the related column number so i can find the X values , X(column_numbers)
Guillaume
Guillaume le 2 Fév 2015
Assumption: t1 and t2 are sorted.
Step 1: find t1 for F >= F_threshold:
t1inrange = t1(F >= F_threshold); %easy
Step 2: find the interval ranges in t1inrange, the answer to that is actually the solution to a cody problem I created a while ago:
stepidx = find(diff(t1inrange) > 1);
t1bounds = t1inrange([1 stepidx+1; stepidx numel(t1inrange)]);
%each column of t1bound is an interval range
Step 3.1: find these bounds in t2. ismember is actually better than intersect for this:
[present, t2idx] = ismember(t1bounds, t2);
if ~all(present)
error('some t1 bounds not found in t2');
end
%each column of t2idx is an interval range on the indices of t2
Step 3.2: expand the interval range t2idx into a sequence of indices, the answer to that is actually the solution to another cody problem I created a while ago:
t2rangeidx = cell(1, size(t2idx, 2));
for col = 1:size(t2idx, 2)
t2rangeidx {col} = t2idx(1, col) : t2idx(2, col);
end
This could also be written as a one-liner using cellfun:
t2rangeidx = cellfun(@(b) b(1):b(2), num2cell(t2idx, 1), 'UniformOutput', false);
Step 3.3: if you want a vector, convert cell array into vector:
t2rangeidx = cell2mat(t2rangeidx);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by