What is "l"?
12 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!