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:
string handling, file reading

Subject: string handling, file reading

From: ben harper

Date: 22 Oct, 2010 06:08:03

Message: 1 of 5

hello, i have such a code. i want to create a vector of strings, read values and read files regarding to the filenames. thank you.

testlist = {'test1' ; 'test2' ; 'test3'}

for i=1:3
    testcode = testlist(i)
    filename=horzcat(testcode,'_measurements.txt')
    data=dlmread(filename,'\t');
    ...
    ...
end

Subject: string handling, file reading

From: Miroslav Balda

Date: 22 Oct, 2010 07:02:05

Message: 2 of 5

"ben harper" <controlusc@gmail.com> wrote in message <i9r9o3$7s5$1@fred.mathworks.com>...
> hello, i have such a code. i want to create a vector of strings, read values and read files regarding to the filenames. thank you.
>
> testlist = {'test1' ; 'test2' ; 'test3'}
>
> for i=1:3
> testcode = testlist(i)
> filename=horzcat(testcode,'_measurements.txt')
> data=dlmread(filename,'\t');
> ...
> ...
> end

Hi Ben
You may replace first two lines in the for-cycle by
    filename=[testlist{i} '_measurements.txt'];
In this case the variable filename will have the required form, i.e. string.
Mira

Subject: string handling, file reading

From: ben harper

Date: 22 Oct, 2010 07:58:04

Message: 3 of 5

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rctc$g9s$1@fred.mathworks.com>...
> "ben harper" <controlusc@gmail.com> wrote in message <i9r9o3$7s5$1@fred.mathworks.com>...
> > hello, i have such a code. i want to create a vector of strings, read values and read files regarding to the filenames. thank you.
> >
> > testlist = {'test1' ; 'test2' ; 'test3'}
> >
> > for i=1:3
> > testcode = testlist(i)
> > filename=horzcat(testcode,'_measurements.txt')
> > data=dlmread(filename,'\t');
> > ...
> > ...
> > end
>
> Hi Ben
> You may replace first two lines in the for-cycle by
> filename=[testlist{i} '_measurements.txt'];
> In this case the variable filename will have the required form, i.e. string.
> Mira

Thank you for your reply Mira.
I need one more thing
How can i use it in such a code?
Thank you

title(['Test name is:',testlist{i}],'t');

Subject: string handling, file reading

From: Miroslav Balda

Date: 22 Oct, 2010 08:46:04

Message: 4 of 5

"ben harper" <controlusc@gmail.com> wrote in message <i9rg6c$imq$1@fred.mathworks.com>...
> "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rctc$g9s$1@fred.mathworks.com>...
> > "ben harper" <controlusc@gmail.com> wrote in message <i9r9o3$7s5$1@fred.mathworks.com>...

> I need one more thing
> How can i use it in such a code?
> Thank you
>
> title(['Test name is:',testlist{i}],'t');

"title" is a command for a plot header. It should have a string as the first argument. The additional arguments are optional for a font control. Therefore, your command should look as it follows:
    title(['Test name is: ',testlist{i}]);
Note spaces after the character ":"! the title would have a string testlist{i} glued on ":".

Mira

Subject: string handling, file reading

From: ben harper

Date: 22 Oct, 2010 13:40:05

Message: 5 of 5

"Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rj0c$knn$1@fred.mathworks.com>...
> "ben harper" <controlusc@gmail.com> wrote in message <i9rg6c$imq$1@fred.mathworks.com>...
> > "Miroslav Balda" <miroslav.nospam@balda.cz> wrote in message <i9rctc$g9s$1@fred.mathworks.com>...
> > > "ben harper" <controlusc@gmail.com> wrote in message <i9r9o3$7s5$1@fred.mathworks.com>...
>
> > I need one more thing
> > How can i use it in such a code?
> > Thank you
> >
> > title(['Test name is:',testlist{i}],'t');
>
> "title" is a command for a plot header. It should have a string as the first argument. The additional arguments are optional for a font control. Therefore, your command should look as it follows:
> title(['Test name is: ',testlist{i}]);
> Note spaces after the character ":"! the title would have a string testlist{i} glued on ":".
>
> Mira

Thank you very much Mira.

Tags for 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