multiple selection of parts of different size matrices
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (1)
Guillaume
le 2 Fév 2015
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
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);
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices 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!