help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: malpractice at num2str + title


From: Fumio Hakamada
Subject: Re: malpractice at num2str + title
Date: Sat, 4 Jul 2020 17:29:56 +0900

Dear Markus,

Thanks for your prompt reply.
My problem was cleared.
All the best.

Hakamada


2020年7月4日(土) 17:04 Markus Mützel <markus.muetzel@gmx.de>:
Am 04. Juli 2020 um 09:55 Uhr schrieb "Benson Muite":
> On 7/4/20 10:46 AM, Fumio Hakamada wrote:
> > t = 1:100;
> > figure
> > for n=1:4
> >      subplot(2,2,n)
> >      a = " deformation - force, n=" + num2str(n);  % no for OCTAVE
> >      y = sin(2*pi*n*t/100);
> >      plot(t,y);
> >      title(a)
> > end
> >
> Try
>
> t = 1:100;
> figure
> for n=1:4
>      subplot(2,2,n)
>      a = strcat(" deformation - force, n=", num2str(n));
>      y = sin(2*pi*n*t/100);
>      plot(t,y);
>      title(a)
> end
>

The reason why Benson's code works but Fumio's doesn't, is that double quotes produce char arrays in Octave but they produce string objects in Matlab.
See also this item on the bug tracker:
https://savannah.gnu.org/bugs/index.php?50855

At the moment, a rule of thumb might be to not use double quotes if you want to write code that should run in Octave and in Matlab.

Markus



--
----------------------------------------
Fumio HAKAMADA, P.E.
fhakamada@gmail.com


reply via email to

[Prev in Thread] Current Thread [Next in Thread]