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!
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
Get Answers For Free
Most questions answered within 1 hours.