如何找到值高于数字的行并绘制其坐标?

时间:2018-03-15 21:08:22

标签: matlab

如果我有这个矩阵M:

M =[0   5   10  15  20  25  30  35  40  45  50  55  60  65  70  75  80  85  90
5   0.284491788  0.312419395 0.327207952 0.334946026 0.339755602 0.342395525 0.344233852 0.345327586 0.346104243 0.34657095  0.346777584 0.346927215 0.347005593 0.347080409 0.347137411 0.347158787 0.347180163 0.347190851
10  0.300057002 0.3301507   0.34627525  0.354729417 0.359959386 0.362862945 0.364882967 0.366055079 0.366878051 0.367362571 0.367583455 0.367754462 0.367839966 0.367925469 0.367986034 0.36800741  0.368028786 0.368039474
15  0.315522463 0.348113577 0.365474367 0.374605437 0.380323489 0.383497809 0.385653212 0.386942891 0.387840678 0.388360825 0.388606648 0.388816844 0.388920161 0.38901279  0.389076918 0.389098293 0.389119669 0.389130357
20  0.331119741 0.366108518 0.384972746 0.39493035  0.401193487 0.404656382 0.406986355 0.408386476 0.409366205 0.409914853 0.410192739 0.410417186 0.410527628 0.410627383 0.41069151  0.410716449 0.410737825 0.410748513
25  0.347347608 0.384858741 0.405034023 0.415832413 0.422576508 0.42631729  0.428864584 0.430410773 0.431440379 0.432053155 0.432352417 0.432580427 0.432708682 0.432811999 0.432883252 0.432908191 0.432929566 0.432940254
30  0.362410488 0.40227297  0.423944565 0.435523175 0.442766041 0.44679896  0.449577826 0.451245146 0.452324629 0.452990844 0.453318608 0.453553743 0.453681998 0.453796003 0.453870818 0.453895757 0.453924258 0.453934946
35  0.376946097 0.419277495 0.442399088 0.454836296 0.462656311 0.466949304 0.469924116 0.47170544  0.472877552 0.473575831 0.473928533 0.474181481 0.474316862 0.474430867 0.474509245 0.474537746 0.474566247 0.474576935
40  0.391574335 0.436360398 0.460981866 0.47432755  0.482721151 0.487341907 0.490491289 0.492386619 0.493615733 0.494395953 0.494762906 0.495019416 0.495179736 0.495304428 0.495389932 0.495418433 0.495446934 0.495464748
45  0.406220385 0.453646371 0.479924472 0.494110941 0.503035377 0.507941145 0.511293598 0.513320745 0.514656739 0.515483273 0.515885853 0.516167302 0.516334747 0.516459439 0.516552068 0.516580569 0.516609071 0.516626884
50  0.420232285 0.470177064 0.497937226 0.513060672 0.522508818 0.527735224 0.531251559 0.533396273 0.534810645 0.53569062  0.536107449 0.536399587 0.53659197  0.53672735  0.536819979 0.536848481 0.536876982 0.536894795
55  0.434824896 0.487441662 0.516933272 0.533000819 0.542951299 0.548448466 0.552196373 0.554465781 0.555937155 0.556867006 0.557319463 0.557640101 0.557850297 0.557992803 0.558085432 0.558113934 0.558142435 0.558160248
60  0.448729916 0.504029356 0.535195411 0.552171435 0.562738252 0.568559621 0.572517724 0.57491895  0.576468702 0.577441305 0.5779187   0.578253589 0.578470911 0.578620542 0.578713171 0.578741672 0.578770174 0.578787987
65  0.462649186 0.520620613 0.553350672 0.571245858 0.582375574 0.588524707 0.592693007 0.595272365 0.59689337  0.597926538 0.598435997 0.598788699 0.599013146 0.59916634  0.599262532 0.599291033 0.599319534 0.599337347
70  0.475371406 0.535943568 0.57038726  0.589212298 0.600933414 0.607378246 0.611746054 0.614475044 0.61617799  0.617257473 0.61779187  0.618158823 0.618390395 0.618550714 0.618650468 0.61869322  0.618721721 0.618739535
75  0.488100752 0.551262959 0.587185151 0.606875913 0.619220492 0.625964587 0.630610282 0.633467526 0.635277352 0.636410275 0.636973173 0.637343689 0.637585949 0.637756956 0.637860273 0.63791015  0.637938651 0.637956464
80  0.499832555 0.565477929 0.602782429 0.623342477 0.636278457 0.643282625 0.648145641 0.651113328 0.653005095 0.654216395 0.654804232 0.655188999 0.655452635 0.65563433  0.655741209 0.655794649 0.65582315  0.655844526
85  0.511222345 0.579325947 0.618169511 0.639670099 0.653136913 0.660465282 0.665520681 0.668634437 0.670593894 0.671844383 0.67247141  0.672877552 0.673148313 0.673340696 0.673451138 0.673504578 0.673533079 0.673554455
90  0.522344936 0.592785635 0.632936692 0.655249564 0.669208023 0.676910471 0.682186754 0.685414514 0.687487976 0.688788343 0.689450996 0.689864263 0.69014215  0.690348783 0.690459225 0.690512665 0.690541166 0.690566105];

我们将仅绘制[,1]和[1,]值: 我们的想法是找到2到19(i,2:19)列的行,其中值大于0.4,并在其各自的列中绘制与条件匹配的行。

选择行的值如下:

selected rows

结果如下:

rows = [45 30 25 25 20 20 20 20 20 20 20 20 20 20 20 20 20 20];
col = [5:5:90];

plot (rows, col);

1 个答案:

答案 0 :(得分:1)

假设每个列按矩阵中的升序排序,您可以将矩阵阈值超过0.4,然后在每列中找到超过此阈值的第一个索引。您可以使用MATLAB中的max函数来帮助您完成此操作。因此,您可以找到每列超过此阈值的行位置,跳过第一列,我们也跳过第一行。然后,您可以使用它来索引第一行,最后绘制数据。请注意,您必须将索引偏移1,因为我们跳过第一行,即第一列:

[~,ind] = max(M(2:end,2:end) > 0.4, [], 1);
rows = M(1, ind + 1);

通过你的例子,我们得到:

>> format compact
>> rows
ans =
    45    30    25    25    20    20    20    20    20    20    20    20    20    20    20    20    20    20

这与您的预期结果一致。