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

Thread Subject: about sprintf.

Subject: about sprintf.

From: salem selma

Date: 15 Jul, 2008 10:09:02

Message: 1 of 5

hi all;

What can i put in my program to know : how often does
message('valid characteristics of the region number%d')
appear?

my program is:

for j=1:10,
if T(:,j)==1%% size of T is=5*10
sprintf('valid characteristics of the region number%
d ',j),
end
end


Thanks.

Subject: about sprintf.

From: us

Date: 15 Jul, 2008 10:21:02

Message: 2 of 5

"salem selma":
<SNIP down to bad syntax...

> if T(:,j)==1%% size of T is=5*10

one of the solutions

% the data (4x2 for sake of brevity...)
     t=[
          1 2
          2 2
          1 1
          2 1
     ];
% the engine
% - any col contains a <1>
     ix=any(t==1,2);
     sprintf('valid region %d\n',find(ix))
%{
     ans =
     valid region 1
     valid region 3
     valid region 4
%}
% - all col must contain a <1>
     ix=all(t==1,2);
     sprintf('valid region %d\n',find(ix))
%{
     ans =
     valid region 3
%}

us

Subject: about sprintf.

From: salem selma

Date: 15 Jul, 2008 12:24:01

Message: 3 of 5

Hi us;

Thanks for your answer but you don't undersand what i
mean; so as your exemple i want to obtain a variable x
which contain number of sentences "valid region "

i remenber your exemple :

 t=[1 2
    2 2
    1 1
    2 1];

 ix=any(t==1,2);
     sprintf('valid region %d\n',find(ix))

ans =
     valid region 1
     valid region 3
     valid region 4



so, my question is: how can i obtain auomatically when
executing this program, x=3 (we have three sentences in
this case)?

Subject: about sprintf.

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

Date: 15 Jul, 2008 14:26:49

Message: 4 of 5

In article <g5i4t1$kib$1@fred.mathworks.com>,
salem selma <salem.selma@mathworks.com> wrote:

>so, my question is: how can i obtain auomatically when
>executing this program, x=3 (we have three sentences in
>this case)?

Either follow the solution you were given yesterday
(the one using the counter named n), or else make the entire
section of code into a quoted string and use evalc() to evaluate
the code and then find the size of the captured output.
--
  "The beauties of conception are always superior to those of
   expression." -- Walter J. Phillips

Subject: about sprintf.

From: us

Date: 15 Jul, 2008 16:15:20

Message: 5 of 5

"salem selma":
<SNIP is not thinking hard enough...

>
> ix=any(t==1,2);
> sprintf('valid region %d\n',find(ix))
> ans =
> valid region 1
> valid region 3
> valid region 4
> so, my question is: how can i obtain auomatically when
> executing this program, x=3 (we have three sentences in
> this case

well, what about

     ns=sum(ix)
% ns = 3

us

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
us salem selma 15 Jul, 2008 08:25:08
sprintf us 15 Jul, 2008 06:25:07
code us 15 Jul, 2008 06:25:06
logical indexing us 15 Jul, 2008 06:25:06
sprintf salem selma 15 Jul, 2008 06:10:08
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