What is "l"?

조회 수: 12 (최근 30일)
Durganshu
Durganshu 2020년 9월 21일
편집: Durganshu 2020년 9월 21일
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.

채택된 답변

Walter Roberson
Walter Roberson 2020년 9월 21일
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
Walter Roberson
Walter Roberson 2020년 9월 21일
편집: Walter Roberson 2020년 9월 21일
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 2020년 9월 21일
편집: Durganshu 2020년 9월 21일
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!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by