简体   繁体   中英

writing function with two outputs

I have written the following code. I would like the function to return the matrices D & S but at the moment it simply returns the matrix 'ans' which is equal to S. Any suggestions would be appreciated. Thanks.

function [D,S] = sdQRS(QRS_cell)
%scales & dilates QRS complexes

m = length(QRS_cell{1}(:,1));
n = length(QRS_cell);


d1 = linspace(0.5,1.0,10);
d2 = linspace(1.0,2.0,21);
d = vertcat(d1',(d2(2:21))');

s1 = linspace(0.6,1.0,13);
s2 = linspace(1.0,1.5,18);
s = vertcat(s1',(s2(2:18))');

DIL = cell(n,1);
SCAL = cell(n,1);
for i = 1:n
    DIL{i} = zeros(m,length(d));
    SCAL{i} = zeros(m,length(d));
    for j = 1:length(d)
        DIL{i}(:,j) = interp1(QRS_cell{i}(:,1),QRS_cell{i}(:,2),QRS_cell{i}(:,1)/d(j),'linear','extrap');
        SCAL{i}(:,j) = s(j)*QRS_cell{i}(:,2);
    end
end

D = zeros(n);
S = zeros(n);
for k = 1:n
    for l = 1:n
        e = [];
        t = [];
        for a = 1:length(d)
            e(a) = euc_dilQ(QRS_cell{k},QRS_cell{l},d(a));
            t(a) = euc_scalQ(QRS_cell{k},QRS_cell{l},s(a));
        end
        [M,E] = min(e);
        [M,T] = min(t);
        D(k,l) = d(E);
        S(k,l) = s(T);
    end
end

You can specify a Matlab function to return any number of output values. In your case the function signature would look something like

function [D,S] = sdQRS(QRS_cell) {
  d1 = linspace(0.5,1.0,10);
  ...
}

Now you can call that function by entering

[D,S] = sdQRS(QRS_cell);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM