I'm stuck on a few questions regarding Matlab programming and would be very appreciative if somebody could help and teach as I'm quite new to it.
1) Given the following operations in Matlab:
>> vec = [6 2 4 1 5 3];
>> idx1 = [0 0 1 1 0 0];
>> idx2 = idx1 == 1;
a) write the values in idx2
b) what is the difference between idx1 and idx2?
c) what is the result of the following assignments? Explain why.
A, >> vec(idx1)
B, >> vec(idx2)
2) A Matlab function requires that an error be generated if an input vector, named vec, contains any element with a value equal to zero. Implement compactly. You may assume the input has already been checked to determine if it is a vector and that it is numeric.
3) There are problems with the following Matlab code.
function vout process(vin, sp, t, pos)
What is wrong with this code? Write correct version.
Would be very appreciative if somebody could help me and also point me in the direction of Matlab tutorials/help/function writing.
(c) Write a Matlab function to count the number of positive values in an
(d) Write a Matlab function that returnstrue if a matrix contains only
(e) Write a Matlab function that returns true is an input argument is not
a numerical array.
(f) There are problems with the following Matlab code.
ans = 5 + 10;What is wrong with this code?
6 + 1;
% Must loop for exactly 15 elements (use ans)
for k = 0:1:ans-1
vec[k] = k;
is missing an "=" between vout and process, also vout seems to be unassigned.Code:function vout process(vin, sp, t, pos) error(nargchk(0,3,nargin))
I cant check error(nargchk(0,3,nargin)) because I would need the matlab help system.
type "help error" and "help nargchk" at the command prompt.