Output argument y issue
3 次查看(过去 30 天)
显示 更早的评论
x=sequence([1 2 3 4 5],-1);
stem(flip(shift(x,2)))
when I enter this on the command window, it says the Output argument "y" (and maybe others) not assigned during call to "sequence/shift".
what did i do wrong?
classdef sequence
properties
data
offset
end
methods
function s = sequence(data, offset)
% SEQUENCE Sequence object
% S = SEQUENCE(DATA, OFFSET) creates sequence S
% using DATA and OFFSET
%
% Your Name 1 Jan 2014
s.data = data;
s.offset = offset;
end
function display(s)
var = inputname(1);
if (isempty(var))
disp('ans =');
else
disp([var '=']);
end
switch length(s.data)
case 0
disp(' data: []')
case 1
disp([' data: ', num2str(s.data)])
otherwise
disp([' data: [' num2str(s.data) ']'])
end
disp([' offset: ' num2str(s.offset)])
end
function y = flip(x)
% FLIP Flip a Matlab sequence structure, x, so y = x[-n]
y=fliplr(x);
end
function y = shift(x, n0)
% SHIFT Shift a Matlab sequence structure, x, by integer amount n0 so that y[n] = x[n - n0]
for i=1:numel(x)
if(i-n0)>0
y(i)=x(i-n0);
end
end
end
function z = plus(x, y)
% PLUS Add x and y. Either x and y will both be sequence structures, or one of them may be a number.
z=x+y;
end
function z = minus(x, y)
% MINUS Subtract x and y. Either x and y will both be sequence structures, or one of them may be a number.
z=x-y;
end
function z = times(x, y)
% TIMES Multiply x and y (i.e. .*) Either x and y will both be sequence structures, or one of them may be a number.
z=x.*y;
end
function stem(x)
% STEM Display a Matlab sequence, x, using a stem plot.
figure
steam(x)
end
end
end
0 个评论
回答(1 个)
Walter Roberson
2019-6-25
Your methods are not static. Input to shift is a sequence object, which you need to extract the data property of.
2 个评论
Walter Roberson
2019-6-26
What does the offset component of the sequence mean? If it means what I suspect it means, then why is it that shift() does not just return a sequence with the same data and a different shift?
I suspect that you intend that object represents a chunk of data at an offset into a vector. If so then is the beginning of the vector offset 0 or offset 1? Is flip() intended to flip the data portion only leaving it at the same offset, or is flip() intended to (generally) change the position as well? For example should flip of _ 1 2 3 _ _ _ _ _ _ be _ 3 2 1 _ _ _ _ _ _ or should it be _ _ _ _ _ _ 3 2 1 _ ? If it is intended to be relative to the entire sequence then each sequence object also needs information about the length of the sequence.
Is the intention that any unfilled locations are 0?
Could you confirm that the intended plus() of sequence([1 2 3],2) and sequence([3 4 5],3) would be like _ 1 2 3 _ _ _ _ _ _ + _ _ 4 5 6 _ _ _ _ _ = _ 1 6 8 7 _ _ _ _ _ = sequence([1 6 8 7], 2) ?
What happens if you shift() data into negative offsets?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!