Function to read a file

조회 수: 23 (최근 30일)
Lev Mihailov
Lev Mihailov 2020년 3월 20일
편집: Rik 2020년 3월 20일
Hello! I have m file for reading ape format files and working with it. Can i make a function like this
% ReadingApe m-file name
ReadingApe('C:/f1p2010.ape')
% and she would give me everything there is
a=[...];
b=[...]
inta=[...]
intb=[...]
now it looks like this
file='C:/f1p2010.ape' % I'm interested in this part, where the file is selected
filedata = fopen(file);
a=fread(filedata) b=fread(filedata)
while
inta=a(i)+1
inta=b(i)+1
end
is it possible to do so, but so that I can choose the files myself?
function ReadingApe
filedata = fopen(file);
a=fread(filedata) b=fread(filedata)
while
inta=a(i)+1
inta=b(i)+1
end
end

답변 (1개)

Rik
Rik 2020년 3월 20일
The function signature below makes more sense to me.
function [a,b,inta,intb]=ReadingApe(file)
Then you can input your variable with the file name. The while loop you have put in your code doesn't make sense, nor the space in the third line of your function, but I'll assume it is just an example.
  댓글 수: 2
Lev Mihailov
Lev Mihailov 2020년 3월 20일
function [a]=ReadingApe('C:/f1p2010.ape')
Error: File: Untitled.m Line: 1 Column: 39
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters,
or other syntax error. To construct matrices, use brackets instead of parentheses.
but I removed the variable in the m file itself
% this is what my m file with a function looks like now
% (it's located in the matlab conner)
function ReadingApe
filedata = fopen(file);
a=fread(filedata) b=fread(filedata)
while
inta=a(i)+1
inta=b(i)+1
end
end
Rik
Rik 2020년 3월 20일
편집: Rik 2020년 3월 20일
That second function doesn't have an input or an output.
%call your function like this
a=ReadingApe('C:/f1p2010.ape')
%define your function like this
function a=ReadingApe(file)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by