Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: character matrix

Subject: character matrix

From: Clem

Date: 15 May, 2008 21:11:40

Message: 1 of 3

Hello everyboby

I would like to generate a matrix of characters. (see below)

S0 = ['ascii_plans_x_1600.dat',
'ascii_plans_x_1800.dat',
'ascii_plans_x_2000.dat',
'ascii_plans_x_2200.dat',
'ascii_plans_x_2400.dat',
'ascii_plans_x_2600.dat',
'ascii_plans_x_2800.dat',
'ascii_plans_x_3000.dat',
'ascii_plans_x_3200.dat',
'ascii_plans_x_3400.dat'];

I am able to generate the name of the file automatically by the following command (each time, the value 1600 is replaced by the value given to 'i')

s = 'ascii_plans_x_1600.dat';
s1 = '1600';
for i=1600:100:4800
    
    s2 = num2str(i);
    X= strrep(s, s1, s2)
end

but I am not able to put them in a matrix. I have the result line by line, I can not link them together.

If someone has an idea, I would really appreciate.

Clementine

Subject: Re: character matrix

From: us

Date: 15 May, 2008 21:36:02

Message: 2 of 3

Clem:
<SNIP string-creation...

one of the many solutions

     tmpl='asc_%4.4d.dat\n';
     r=strread(sprintf(tmpl,1600:100:2000),'%s');
     r=char(r)
%{
     r=
     asc_1600.dat
     asc_1700.dat
     asc_1800.dat
     asc_1900.dat
     asc_2000.dat
%}

us

Subject: Re: character matrix

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 15 May, 2008 21:43:29

Message: 3 of 3

In article <28364413.1210885931460.JavaMail.jakarta@nitrogen.mathforum.org>,
Clem <c_vezier@hotmail.com> wrote:
>Hello everyboby

>I would like to generate a matrix of characters. (see below)

>S0 = ['ascii_plans_x_1600.dat',
>'ascii_plans_x_1800.dat',
>'ascii_plans_x_2000.dat',
>'ascii_plans_x_2200.dat',
>'ascii_plans_x_2400.dat',
>'ascii_plans_x_2600.dat',
>'ascii_plans_x_2800.dat',
>'ascii_plans_x_3000.dat',
>'ascii_plans_x_3200.dat',
>'ascii_plans_x_3400.dat'];

Note that comma (',') is the horizontal concatenation operator,
so the result of the above would be a single long string.

If every line in the array is exactly the same size, change the
commas to semicolons (';') to use the vertical concatenation operator:

S0 = ['ascii_plans_x_1600.dat';
'ascii_plans_x_1800.dat';
'ascii_plans_x_2000.dat';
'ascii_plans_x_2200.dat';
'ascii_plans_x_2400.dat';
'ascii_plans_x_2600.dat';
'ascii_plans_x_2800.dat';
'ascii_plans_x_3000.dat';
'ascii_plans_x_3200.dat';
'ascii_plans_x_3400.dat'];

If you need an array in which the strings can be different sizes, then
you should use a cell array:

S0 = {'ascii_plans_x_1600.dat',
'ascii_plans_x_1800.dat',
'ascii_plans_x_2000.dat',
'ascii_plans_x_2200.dat',
'ascii_plans_x_2400.dat',
'ascii_plans_x_2600.dat',
'ascii_plans_x_2800.dat',
'ascii_plans_x_3000.dat',
'ascii_plans_x_3200.dat',
'ascii_plans_x_3400.dat'};

Notice the change from [] to {}.
--
  "I think Walter's legacy will be that of a man with a God-given
  ability that got the most out of it at every possible chance."
                                                  -- Eddie Payton

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
strread us 15 May, 2008 17:40:22
code us 15 May, 2008 17:40:22
sprintf us 15 May, 2008 17:40:22
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics