I am trying to write a simple implementation of a stack in MATLAB, I have used a piece of code earlier in my work similar to:
A = zeros(5,3)
[x, y] = size(A)
This, as expected assigns x to 5, and y to 3, as desired, however I have tried to do a similar thing in my stack implementation and it's throughing an error:
function [x, y] = pop(obj)
[x, y] = obj.Data(1, :);
obj.Data(1, :) = [];
end
Error: Indexing cannot yield multiple results.
I tried to first extract the 2x1 matrix and then assign it, but that didn't work either:
function [x, y] = pop(obj)
top = obj.Data(1, :);
[x, y] = top;
obj.Data(1, :) = [];
end
Error: Too many output arguments
This seems strange to me and an explanation of why this occurs would be very interesting, as well as a work around for this
Thank you.
objis? What istopthat comes out? If, as you state, top is a 2x1 matrix, you have to extract the values withx = top(1,1)andy = top (2,1).objis a 2xn matrix.