如何对跳转列中的值进行排序? [英] How can I sorting the values in the jumping columns?

查看:37
本文介绍了如何对跳转列中的值进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个25x600的矩阵,有些列包含正值和负值.我想要这样的输出[+ +--](四个值2正和2负).我保证总是在过渡之前立即有两个正值,在过渡之后立即有两个负值.我的尝试如下:

I have a matrices 25x600 and some columns contains positive and negative values. I want the output like this [+ + - -] (four values 2 positive and 2 negative). I am guaranteed to always have two positive values immediately before the transition and two negative values immediately after. my attempting was as follow :

我的尝试如下:

    clc;
    clear all;
    close all;
    %%
    data=[-0.0059972;-0.004994;-0.0029881;2.0868e-05;
0.0030299;0.013059;0.033115;0.063196;0.093273;0.1935;0.39385;0.69423;0.99448;1.9950;3.99550;6.99550;9.9957;19.9961;39.99620;69.9960;
99.99530;199.99810;399.99140;699.98860;1000.03130]
    for r=1:600
        lam=data(:,r);
        N_lam = length(lam);
        %%
        for j=1:N_lam
            kk=0;
            r1=0;
            if(sign(lam(j))==1)
                kk=kk+1;
                lampos(kk)=lam(j);
                if (length(lampos(kk))>3 &length(lamneg(r1))>2)
                 break
                end
            else
                r1=r1+1;
                lamneg(r1)=lam(j);
            end
        end
        cc{r}=[lampos lamneg];
    end

任何帮助将不胜感激.

推荐答案

find函数在此处可能很有用,因为它可以帮助您找到函数从正变为负的位置.下面的代码在data的最后一个负值(假定为一维矢量)升到零以上之前找到它的索引ind:

The find function may be useful here, as it can help you to locate the locations where the function changes from positive to negative. The following locates the index ind of the last negative value of data (assumed here to be a 1D vector) before it rises above zero:

num_rises = 1;
ind = find(data(1:end-1)<=0 & data(2:end)>0, num_dips, 'first')

因此,对于每一列,您都会对ind-1,ind,负值和ind+1,ind+2的正值感兴趣.

As such, for each column, you would be interested in the values of ind-1,ind, negative values, and ind+1,ind+2 for the positive values.

我也不清楚这4个值中有多少套您感兴趣.要查找数据低于原点的更多区域,请更改num_dips的值以适合您的需求.

It was also unclear to me how many sets of these 4 values were of interest to you. To find more regions where the data dips below the origin, change the value of num_dips to suit your needs.

这篇关于如何对跳转列中的值进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆