Question

In matlab how to make it that i can be able to type in the file...

In matlab how to make it that i can be able to type in the file that I would like to test and to be able to test what algorithm i have. This is what i have so far. But I need help fixing the rest. Please help I need this asap.

function FunctionAlgorithm()
disp("Welcome to ___________ algorithm")
filename =
file = input('Type in the file to test: ');
number = input('Type the number of the algorithm you want to run.');

end

How can I fix this?

Thanks!

Homework Answers

Answer #1

For this you need to know the line that your Algorithm starts and ends

Matlab code --

function line= FunctionAlgorithm() %this function returns matrix line which contains required lines from file. On this matrix line, %the algorithm can be ran in separate function or in script

fid = fopen('filename','rt');

nlines = 0; %calculating no of lines in file

while (fgets(fid) ~= -1),

nlines = nlines+1;

end

fclose(fid);

C = textread('filename', '%s','delimiter', '\n');

lm1=3; % starting line to read (taking 3 for example)

lm2=7; %end line to read (taking 7 for example)

temp=1;

lm=lm1;

while lm <= lm2 && lm <=nlines

line(temp,:)=C{lm};

lm=lm+1;

temp=temp+1;

end

end

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a function called char_counter that counts the number of a certain character in a text...
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...
I have already written a MATLAB code to filter noise from a particular audio file however...
I have already written a MATLAB code to filter noise from a particular audio file however the resulted audio is not playing I use this code snippet: presult = audioplayer(fOut, fs); presult.play; the fout is fOut = filter(b, a, f); I do not know what i am doing wrong as the output playing is still the initial sound not thr noise filtered one. Please help deadline is due in hours. Thanks in advance
How can I write a function in MATLAB with an input of array1 and an output...
How can I write a function in MATLAB with an input of array1 and an output of maxValue (being the highest value in array 1) without calling the built in function in MATLAB. I ned to use a loop to accomplish this.
I have this HW for intro to engineering and i am struggling to type it into...
I have this HW for intro to engineering and i am struggling to type it into MATLAB, can you please explain how i can type it in 1- Solve following equations using MATLAB and send your output here. (Output could be a screen shot or MATLAB file): a) x-14=-2y-3z b) 40-4x=6y+8z c) x+3y+7z-28=0 2- Plot following function in MATLAB and send your output here. (Output could be a screen shot or MATLAB file): Y = X . COS(X) . SIN(X)...
Trying to change all the characters in goodStuff file to uppercase. I want to use tr...
Trying to change all the characters in goodStuff file to uppercase. I want to use tr '[a-z]' '[A-Z]' but don't know how to do the rest. Can you help?
Can someone show me how to simulate a PID controller in matlab. I am bad at...
Can someone show me how to simulate a PID controller in matlab. I am bad at coding and want to see how to do a PD, PI, and PID in matlab.
i have a file named players.dat that has these names as their usernames and passwords //players.dat...
i have a file named players.dat that has these names as their usernames and passwords //players.dat mickeymouse clubhouse goofy gawrsh donaldduck phooey pluto bloodhound minniemouse polkadot I want to read from this and input this into a vector, im new to vectors so can someone please help. And dont use a sstream.
I need to make a model in MATLAB for free-fall using Euler method. g=9.81 (gravitational acceleration)...
I need to make a model in MATLAB for free-fall using Euler method. g=9.81 (gravitational acceleration) c=12.5 (drag coefficient) m= 68.1 (mass) h=0.1 (step size) v(0)=0 (Velocity is 0 at time zero) t=[0:100]*h (100 steps) Vnew= vt+(g-(c/m)*v)*h (this is the equation for the velocity at each subsequent step I want to use a "for" loop in MATLAB but i don't know how to write it properly. Could anyone help me?
Write Matlab function script that you developed in such that it will take a real number...
Write Matlab function script that you developed in such that it will take a real number p and a desired tolerance TOL as input and will return the cube-root and number of iterations as output. You need to use a while(1) or infinite loop. Use your function to determine the cube roots of : (a) 81 I am getting stuck on how i can use a while loop for this. Any help would be much appreciated.
How would I solve these python problems? A) File Display Download the file from here named...
How would I solve these python problems? A) File Display Download the file from here named numbers.txt . Write a program that displays all of the numbers in the file. numbers.txt contains 22 14 -99 AB B) Error Check Float Input When you want an int input you can check the input using the string isdigit() method. However, there is no comparable check for float. Write a program that asks the user to enter a float and uses a try-except...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT