From: dpb on
Peter wrote:
....

> The function testa will create a 100x5 matrix with each column being
> 1-100 then each number to the power of x for that column:
>
> [ 1^1 1^2 1^3 1^4 1^5]
> 2^1 2^2 2^3...
> 3^1 3^2..
>
> Now I did this by:
>
> ======= testa.m=======
> function y = testa(x)
> % x is the array of numbers to use
> % ..
> w=(1:100)'; % wavelength from 0.02um to 100um
> for i=1:numel(x)
> y(:,i)= w.^i;
> end
> end
> ================
>
> but I probably don't even need to do this??
....

Indeed, you will want to try to forget most of what you know about
writing code a la VB (or any other similar procedural language that
doesn't support array syntax). While you can code in Matlab that way,
you lose most of its power, not to mention that it will be much slower
in execution that way than by the use of the builtin functions and methods.

For the specific problem, try exploring

>> [x,y]=meshgrid(1:10,1:5);
>> x.^y'

at command line...note this relates to what I alluded to earlier about
vectorizing your planck function for both variables simultaneously...

--
From: Peter on
>
> Indeed, you will want to try to forget most of what you know about
> writing code a la VB (or any other similar procedural language that
> doesn't support array syntax). While you can code in Matlab that way,
> you lose most of its power, not to mention that it will be much slower
> in execution that way than by the use of the builtin functions and methods.
>
> For the specific problem, try exploring
>
> >> [x,y]=meshgrid(1:10,1:5);
> >> x.^y'
>
> at command line...note this relates to what I alluded to earlier about
> vectorizing your planck function for both variables simultaneously...
>
> --

Thanks very much for taking the time - and also to Jan.

It's a real help to have someone dive in and explain the specific point where you have gone wrong. 2 hours reading the wrong help or the right help but misunderstanding it - or a few minutes getting help from someone.

Much appreciated.

I think Matlab should do a "if you've used VB before, then read this help file.."
From: Peter on

>
> For the specific problem, try exploring
>
> >> [x,y]=meshgrid(1:10,1:5);
> >> x.^y'
>
> at command line...note this relates to what I alluded to earlier about
> vectorizing your planck function for both variables simultaneously...
>
> --

You are right about meshgrid - awesome. I just create the x values (wavelength) and the y values (temperatures) using meshgrid in a few seconds, then one command to create the result and surf or mesh to plot in 3d. About 300x faster than anything else.

I did have a question (of course) - I ran mesh on my output: mesh(z)

But the x and y values on the plot weren't the x and y values I had created - it was as if they were just the ith value and the jth value in the array.

The help on mesh showed an example which automatically created the correct x and y values..

[x,y]=meshgrid(.1:.1:30,200:50:1000);
z=planck(x,y);

and the result shows 1-300 on the x-axis - 300 values - instead of 0.1 - 30.
What is needed?
Thanks.
From: us on
"Peter " <pgillies3(a)gmail.com> wrote in message <i2jqch$blk$1(a)fred.mathworks.com>...
>
> >
> > For the specific problem, try exploring
> >
> > >> [x,y]=meshgrid(1:10,1:5);
> > >> x.^y'
> >
> > at command line...note this relates to what I alluded to earlier about
> > vectorizing your planck function for both variables simultaneously...
> >
> > --
>
> You are right about meshgrid - awesome. I just create the x values (wavelength) and the y values (temperatures) using meshgrid in a few seconds, then one command to create the result and surf or mesh to plot in 3d. About 300x faster than anything else.
>
> I did have a question (of course) - I ran mesh on my output: mesh(z)
>
> But the x and y values on the plot weren't the x and y values I had created - it was as if they were just the ith value and the jth value in the array.
>
> The help on mesh showed an example which automatically created the correct x and y values..
>
> [x,y]=meshgrid(.1:.1:30,200:50:1000);
> z=planck(x,y);
>
> and the result shows 1-300 on the x-axis - 300 values - instead of 0.1 - 30.
> What is needed?
> Thanks.

well... didn't you give the answer yourself(?)...
it all depends on what PLANCK does - or the subsequent call to MESH(), once you obtain your Z from the data...

us
First  |  Prev  | 
Pages: 1 2 3
Prev: A possible bug in Windows Server 2008?
Next: reshape