Hello everyone,
I recently bought a book on Inverse Synthtic Aperture Radars and it contains many MATLAB codes for verifying the results shown in the book. One such MATLAB function is as follows:
function [out]=shft(A,n)
%This function shifts (circularly) the vector A with
% an amount of n
% Inputs:
% A : the vector to be shifted
% n : shift amount
% Output:
% out : shifted vector
out = A(l-n+2:l);
out(n:l) = A(1:l-n+1);
However, there is no reference or assignment to "l". Further, the code which actually utilizes this function dosesn't assigns any value to "l" (So, "l" is missing from it as well).
This code was most probably written around 2011 or even earlier. Was "l" used for any particular notation at that time and now, that notation has been vanished with updates in MATLAB? I'll use the newer notations or update the code if necessary.
Kindly help me with this.

 Accepted Answer

Walter Roberson
Walter Roberson on 21 Sep 2020
No, l did not have any special meaning.
Is it possible that this is a nested function? Was there an end statement after what you posted, and was it defined inside another function, like
function outer
l = 7
A = rand(1,25);
n = 3;
disp(shft(A,n))
function out = shft(A,n)
out = A(l-n+2:l);
end
end

5 Comments

Durganshu
Durganshu on 21 Sep 2020
Edited: Durganshu on 21 Sep 2020
Thank you Walter. However, there is no nested function. shft is standalone function and has been used in many other progarmmes.
for nn=1:250
[A,ix] = max(max(ISARres));
[dum,iy] = max(max(ISARres.'));
hsincX = shft(hsncF,ix);
hsincY = shft(hsncPHI,iy);
hhsinc = hsincX.'*hsincY;
ISARres = ISARres-A*hhsinc.';
SSs(nn,1:3) = [A XX(ix) YY(iy)];
II=ISARres;
II(1,1) = Amax;
% Image Reconstruction
ISARbuilt = ISARbuilt-A*hhsinc.';
end
This is the snippet of code I'm currently working on and it contains the usage of shft. There's no reference to l anywhere before or after this snippet. I get the following error after runing this code:
Undefined function or variable 'l'.
Error in shft (line 12)
out = A(l-n+2:l);
Error in Figures7_2thru7_8 (line 79)
hsincX = shft(hsncF,ix);
Walter Roberson
Walter Roberson on 21 Sep 2020
All I can think of is that there might have been a function l.m
Based on context, l appears to be the same as end .
Is it possible that there is an import statement in the code?
Durganshu
Durganshu on 21 Sep 2020
Yes, even I tried switching it with end. But, it didn't work.
There are 2 load statements in the code, both used to load two .mat files as input. However, there isn't any import statement.
Further, I also didn't find any function l.m in the repository provided by the author.
Walter Roberson
Walter Roberson on 21 Sep 2020
Edited: Walter Roberson on 21 Sep 2020
Reading through the code more carefully, l would have to be length(A) rather than the literal end . And the meaning of n would be strange. n is described as the amount to shift, but if n is 1 then the code would have no shift, and if n is 2 then the code would shift one element from the end to the beginning. If n was 0 or less then the code would generate an error.
I am not bothered so much by 0 or negative being invalid (though shift of 0 should be well defined as just returning the original), but shift of 1 should not be returning the original.
I think the code is buggy.... Unless it is the documentation that is buggy, and that the real definition is that n is the index that is to be moved to the first position -- in which case a value of 1 would not require any data movement, a value of 2 would move by 1 and so on.
Durganshu
Durganshu on 21 Sep 2020
Edited: Durganshu on 21 Sep 2020
Hey roberson!!!!!
You were right. l is the length of A. I extracted l using max(size(A)) and then re-ran the code and thankfully, it worked.
Thanks!!!

Sign in to comment.

More Answers (0)

Categories

Products

Tags

Asked:

on 21 Sep 2020

Edited:

on 21 Sep 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!