Indexing to create a new array
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Kate
am 11 Nov. 2013
Kommentiert: Marc
am 12 Nov. 2013
I have a very simple question, but just can't seem to wrap my brain around the answer today.
My index:
>> Wtr
Wtr =
12
1
2
My data:
mNEE =
1.0000 NaN
2.0000 NaN
3.0000 0.2165
4.0000 3.9982
5.0000 18.3253
6.0000 32.6099
7.0000 14.7678
8.0000 36.8627
9.0000 -1.0730
10.0000 -8.2807
11.0000 6.7998
12.0000 25.0182
1.0000 8.1078
2.0000 0.7304
3.0000 -6.2877
4.0000 -2.5207
5.0000 10.5052
6.0000 11.2116
7.0000 4.8839
8.0000 -8.1560
9.0000 -16.8618
10.0000 -45.3915
11.0000 -39.8423
12.0000 -8.4954
1.0000 13.1454
2.0000 31.7136
3.0000 41.5338
4.0000 19.9113
5.0000 18.7724
6.0000 -20.1884
7.0000 -7.9781
8.0000 -12.7571
9.0000 -21.3081
10.0000 -18.9930
11.0000 -31.7573
12.0000 -7.2601
1.0000 10.2586
2.0000 16.4023
3.0000 45.1588
4.0000 24.6945
5.0000 0.0275
6.0000 7.3914
7.0000 -3.5258
8.0000 -15.4096
9.0000 -19.4229
10.0000 -21.2903
11.0000 -11.5092
12.0000 -55.0183
1.0000 -53.4840
2.0000 -4.5846
3.0000 14.0066
4.0000 0.5472
5.0000 31.4220
6.0000 8.1386
7.0000 -13.0516
8.0000 -2.7136
9.0000 NaN
10.0000 NaN
11.0000 NaN
12.0000 NaN
All that I really want to do is pull data where the 1st column of mNEE==Anything in Wtr.
But when I run this super simple for loop I only get the first 3 matches, when I want all the data that falls within the category of Wtr in a new array:
for i=1:length(mNEE)
t=mNEE(Wtr,:);
end
>> t
t =
12.0000 25.0182
1.0000 NaN
2.0000 NaN
Could someone please help me understand why Matlab finds the first 3 matches, but not anymore? This seems so simple but is eluding me.
Thanks a million.
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 11 Nov. 2013
Try this:
matchingRows = ismember(mNEE(:,1), Wtr)
extractedRows = mNEE(matchingRows, :)
3 Kommentare
Weitere Antworten (1)
Azzi Abdelmalek
am 11 Nov. 2013
Bearbeitet: Azzi Abdelmalek
am 11 Nov. 2013
mNEE =[1.0000 NaN
2.0000 NaN
3.0000 0.2165
4.0000 3.9982
5.0000 18.3253
6.0000 32.6099]
wtr=[12;1;2]
idx=ismember(mNEE(:,1),wtr)
mNEE(idx,:)=[]
%or
data=mNEE(~idx,:)
5 Kommentare
Siehe auch
Kategorien
Mehr zu Data Distribution Plots 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!