Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Problem with fopen

Subject: Problem with fopen

From: Serko Tsalikian

Date: 13 Sep, 2010 14:24:24

Message: 1 of 4

I have let's say some texts with names Sp1.txt ,Sp2.txt ,Sp3.txt and i want to read them in a 'for' by using i=i+1; with a command like this:<fid=fopen('Sp(i).txt');> I don't want to use three times the command by changing the number like this <fid=fopen('Sp1.txt'); fid=fopen('Sp2.txt'); fid=fopen('Sp3.txt');> How is this possible to be done.

Subject: Problem with fopen

From: Sean

Date: 13 Sep, 2010 14:59:07

Message: 2 of 4

"Serko Tsalikian" <serkoulik@yahoo.gr> wrote in message <i6lc6o$fuv$1@fred.mathworks.com>...
> I have let's say some texts with names Sp1.txt ,Sp2.txt ,Sp3.txt and i want to read them in a 'for' by using i=i+1; with a command like this:<fid=fopen('Sp(i).txt');> I don't want to use three times the command by changing the number like this <fid=fopen('Sp1.txt'); fid=fopen('Sp2.txt'); fid=fopen('Sp3.txt');> How is this possible to be done.

for ii = 1:3 %use ii since i=sqrt(-1)
   fid = fopen(['Sp' num2str(ii) '.txt']); %convert ii to string
...
end

Subject: Problem with fopen

From: Steven_Lord

Date: 13 Sep, 2010 17:26:31

Message: 3 of 4



"Serko Tsalikian" <serkoulik@yahoo.gr> wrote in message
news:i6lc6o$fuv$1@fred.mathworks.com...
> I have let's say some texts with names Sp1.txt ,Sp2.txt ,Sp3.txt and i
> want to read them in a 'for' by using i=i+1; with a command like
> this:<fid=fopen('Sp(i).txt');> I don't want to use three times the command
> by changing the number like this <fid=fopen('Sp1.txt');
> fid=fopen('Sp2.txt'); fid=fopen('Sp3.txt');> How is this possible to be
> done.

See question 4.12 in the newsgroup FAQ.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Problem with fopen

From: Serko Tsalikian

Date: 13 Sep, 2010 18:01:05

Message: 4 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i6le7r$1lt$1@fred.mathworks.com>...
> "Serko Tsalikian" <serkoulik@yahoo.gr> wrote in message <i6lc6o$fuv$1@fred.mathworks.com>...
> > I have let's say some texts with names Sp1.txt ,Sp2.txt ,Sp3.txt and i want to read them in a 'for' by using i=i+1; with a command like this:<fid=fopen('Sp(i).txt');> I don't want to use three times the command by changing the number like this <fid=fopen('Sp1.txt'); fid=fopen('Sp2.txt'); fid=fopen('Sp3.txt');> How is this possible to be done.
>
> for ii = 1:3 %use ii since i=sqrt(-1)
> fid = fopen(['Sp' num2str(ii) '.txt']); %convert ii to string
> ...
> end


thanxs a lot my friend. It worked!

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us