Hi guys i'm new to this software package and require some assistance on making 2 function M-files...
1)Write a function file replace that replaces all elements in a row vector that are between -2 and +2 by 0. The function file should operate on row vectors of arbitrary length. You are not allowed to use the Matlab function find.
Hints: Use a for loop and an if statement. The length of a row vector x can be
obtained using the Matlab command length(x).
2) Write a function file FindPositive that takes in a row vector of arbitrary length and returns the first positive value in the row vector, as well as the index of the row vector where the first positive value occurred. You are not allowed to use a for loop or an if statement in your solution.
for the 1st one i was doing somethin along the lines of
(Can't check my code till monday now don't have matlab on my pc only on the uni pc's)Code:function b=replace(a) %This function replaces all elements in a row or column that are %between 2 and -2 with 0 and assisns the new elements to the row b L=length(a); for k=1:L if a(k)<2|a(k)>-2 b(k,1)=0; else b(k,1)=a(k); end end
For the second one still not sure as i dunno how to use the find function as of yet >.< !
FreeMat for basic matlab coding jobs, its free and pretty good.
The or in your code should be an and (and last time I looked the editor wanted me to use || and && rather than | and &, but both seem to still work)
A complete distribution is available to students to turn them into Matlab users for life, so when they get jobs they will want their employers to provide Matlab as their tool of choice. Now here is the rub, the Matlab installation on my work machine is by no means complete and it has cost my employer about £10000 to provide + annual maintenance fees (there is a basic price for the Matlab core functionality then ca £600 per additional toolbox and you need a fair number of those tool boxes).
Educational institutions should not be aiding in this conspiracy.
Employers with a corporate policy of not using open source software (yes, I'm looking at you RandomTLA-Systems) are also to blame for this situation (assuming their accounting systems give them any indication of how much they are paying MathWorks for those 1000's of Matlab seats)
(I won't mention the ludicrous amount of time it takes Matlab to boot, when using an alternative I will have solved the kind of small problem that often comes up before Matlab will have booted)