Prev: A possible bug in Windows Server 2008?
Next: reshape
From: dpb on 24 Jul 2010 13:22 dpb wrote: .... > Works here. One thing I note is an unmatched "end" statement in your > function listing which makes me think there's something not being shown > here. As written otherwise should work afaict. .... Forgot to mention...do which planck and I suspect it'll show another old copy being called instead of the one you think is being referenced... --
From: Peter on 24 Jul 2010 19:58 Thanks for your excellent help- > > Works here. You are right. I copied your code and it worked and then I copied the code out of my old script into the command window and it worked.?? So I have deleted that script file. > > > And what I was trying to do was create an array, y, the same size as w - > > not replace y with a new value each time through. > > As you wrote it, you don't need the loop for the one variable--that's > what the .*, ./ operators do is to evaluate on an element-by-element > basis to eliminate loops; Matlab's strength. Now if you want to do both > variables simultaneously, you'll need to build a grid or somesuch, but > as you've written it, planck() will return the vector directly. > > >> y = planck([.2:.2:100], 290); > >> length(y) > ans = > 500 > >> Ok, I see - that worked. What is surprising is that I can't seem to find a section in the Matlab help that really works through these ideas. Lots of stuff about magic matrices and mulitplying matrices together or inverting them - but not a step by step how to create a set of functions to work on a series of numbers - if you can point me towards something (it must exist!!) I would appreciate it. What I am trying to do is first to have the planck function, then to have a function which builds the complete set for all values of w - like you show above - but where I input a temperature (instead of 290) I tried it and again failed. The intention of this function below is to return a 1d array with the planck curve. ========planckf.m==== function planckf(t) % produce the complete planck curve for temperature t w=(.02:.02:100)'; % create column vector for wavelength planckf = planck(w,t); end ================== when I run it - y = planck(290); the command window says: ??? Input argument "t" is undefined. Error in ==> planck at 4 ri = 3.742E8.*(pi.*w.^5.*exp((1.439E4./(w.*t))-1)).^-1; ---and then I was going to use this function as a building block in a script or function to create 10 curves of different temperatures. Seems like it should be really easy.. hours later.. there must be a tutorial on something very close to this.. Thanks for the help so far.
From: Walter Roberson on 24 Jul 2010 20:09 Peter wrote: > ========planckf.m==== > function planckf(t) > % produce the complete planck curve for temperature t > w=(.02:.02:100)'; % create column vector for wavelength > planckf = planck(w,t); > end > ================== > > when I run it - y = planck(290); > > the command window says: > > ??? Input argument "t" is undefined. Your new function is named planckf but you are invoking the function planck (without an f)
From: Peter on 24 Jul 2010 21:09 > > Your new function is named planckf but you are invoking the function > planck (without an f) Thanks, you are right! Ok now that works (once I fixed the fact that nothing was output from the function). I realize that I am trying to use Matlab like VB and it probably does what I want much much easier So I set a different problem to try and more easily find my many syntax issues: Send a 1d row array, x = (1,2,3,4,5) into a function, testa. 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?? Any suggestions to simplify even further? Thanks again.
From: Jan Simon on 24 Jul 2010 21:09
Dear Peter, > ---and then I was going to use this function as a building block in a script or function to create 10 curves of different temperatures. Seems like it should be really easy.. hours later.. there must be a tutorial on something very close to this.. Did you try to set a breakpoint in "plankf" for the debugger? Then you'd see, that your function "planckf" is not entered. The debugger assists you in finding bugs. It is the most useful part of Matlab. Processing the code line by line tells you exactly, what's going on. As example for a working function, take a look in some of the toolbox functions, e.g. MEAN: edit mean There you find a smart example of how to call other function like SUM and SIZE and NARGIN. It is impossible to write a manual about avoiding typos. It still looks, like you have confused something tiny. My advice is to take a cup of coffee (what's the time at you) or any other kind of break, restart Matlab and try it again. Remember: all you have posted here was valid code, so actually you are prepared to solve your problem. Good luck, Jan |