permute function in matlab/octave

Go To StackoverFlow.com

2

I have a working matlab/octave m file but when I convert the M file to a function and run it I get an error in the function saying 'function name' undefined near line 7 column 16.

See workng M file below:

clear all, clc,clf,tic
fs=360; 
t=linspace(0,2*pi,fs);
y=sinc(t*1);
sigarray=y;

fs=length(sigarray);
aa_sig_combined_L=zeros(1,length(fs)); %need to reset or will get noise at the end
a_L=zeros(1,length(sigarray));

cycle_permute_lt = @(sigarray, k) [sigarray(mod((1:end)+k-1, end)+1 )];
array_phase_shift_div_num=360/mod(180,360) %keep at 360 to get correct deg angles
array_phase_shift=round(fs/array_phase_shift_div_num) %will keep within 360 degs

for ii=0:1:fs
    a_L=cycle_permute_lt(sigarray, ii+array_phase_shift);
    aa_sig_combined_L = aa_sig_combined_L + a_L;        

end;
array_shifted=aa_sig_combined_L;

subplot(2,1,1),plot(t,y),
title('original')
subplot(2,1,2),plot(t,aa_sig_combined_L)
str_title='aa_sig_combined_L'; 
title(str_title,'Interpreter','none') %turns of latex interperter so I can use underscores my way

See M file and Function created below that doesn't work when accessed

clear all, clc,clf,tic
fs=360; 
t=linspace(0,2*pi,fs);
y=sinc(t*1);
sigarray=y; 
[array_shifted]=rtpsa(y,180)

Function below:

function [array_shifted]=rtpsa(sigarray,deg_to_shift)
    fs=length(sigarray)
    aa_sig_combined_L=zeros(1,length(fs)); %need to reset or will get noise at the end
    a_L=zeros(1,length(sigarray));

    cycle_permute_lt = @(sigarray, k) [sigarray(mod((1:end)+k-1, end)+1 )];
    array_phase_shift_div_num=360/mod(deg_to_shift,360) %keep at 360 to get correct deg angles
    array_phase_shift=round(fs/array_phase_shift_div_num) %will keep within 360 degs

    for ii=0:1:fs
        a_L=cycle_permute_lt(sigarray, ii+array_phase_shift);
        aa_sig_combined_L = aa_sig_combined_L + a_L;        

    end;
    array_shifted=aa_sig_combined_L;

end;

I'm using octave version 3.2.4 and ubuntu 10.04 linux

2012-04-04 19:24
by Rick T
perhaps you should change the title of this post to 'function name' undefined in octave as the nature of this problem has nothing to do with the permute function - zeffii 2012-11-09 18:03


-1

Sorry guys I fixed the problem when editing the function file in a different text editor it changed the .m extension to a .m.txt file.

2012-04-04 22:13
by Rick T
The issue here was most probably the newline setting in your Text editor, 'nix and window have slightly different defaults, one uses CR+LF and the other just uses LF. But what is used is a matter of preference in individual applications. Perhaps an interesting read: https://en.wikipedia.org/wiki/Newlin - zeffii 2012-11-09 16:50


0

This should have been an answer instead of a comment:

The issue here was most probably the newline setting in your Text editor, 'nix and window have slightly different defaults, one uses CR+LF and the other just uses LF. But what is used is a matter of preference in individual applications.

Perhaps an interesting read: wikipedia on newlines

2012-11-09 18:01
by zeffii
Ads