I should mention however that I have two different vectors, lets say specific_time_points1 and specific_time_points2 that have the same timeline. And my new vector indicator should contain a 1 where specific_time_points1 and/or specific_time_points2 are in the timeline and zero every where else.
finding al points of a vector in my array and assigning them a different number.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Lois Slangen
am 14 Aug. 2019
Kommentiert: Andrei Bobrov
am 14 Aug. 2019
Hi, I have specific timespoints along my timeline that I want to assign a diiferent number. So let's say I have a timeline from 1 to 2000 and I have a vector with a different amount of time points that are somewhere on my timeline (so between 1 and 2000). I want to create a new vector, called indicator, where all the specific time points are assigned a value of 1 and where all the other time points in my timeline are assigned 0. Here is what I have:
counter = 0;
for ii = 1:length(timeline)
if ii == specific_time_points
counter = counter + 1;
indicator (counter) = ii;
indicator = 1;
else indicator = 0;
end
end
But, 'indicator' now only has one value of 0, instead I want it to give a vector of length 2000 with 1's were my specific_time_points are and zeros for the rest of my timeline.
I don't know what I am doing wrong, I hope someone can help me.
Akzeptierte Antwort
Andrey Kiselnikov
am 14 Aug. 2019
Hi here it is
a = 1:1:10;
b = [1 3 5];
>> ismember(a,b)
ans =
1×10 logical array
1 0 1 0 1 0 0 0 0 0
If my help was useful please mark answer as accepted!
5 Kommentare
Andrey Kiselnikov
am 14 Aug. 2019
Bearbeitet: Andrey Kiselnikov
am 14 Aug. 2019
indicator_1 = ismember(timeline,specific_time_points1);
indicator_2 = ismember(timeline,specific_time_points2);
indicator = indicator_1 | indicator_2;
it was for better understanding, in one line it looks like
indicator = ismember(timeline,specific_time_points1) | ismember(timeline,specific_time_points2);
Andrei Bobrov
am 14 Aug. 2019
indicator = ismember(timeline,...
[specific_time_points1(:);specific_time_points2(:)]);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!