What is "l"?
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Durganshu
am 21 Sep. 2020
Bearbeitet: Durganshu
am 21 Sep. 2020
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.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 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 Kommentare
Walter Roberson
am 21 Sep. 2020
Bearbeitet: Walter Roberson
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu File Operations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!