Prev: How to search text file for a string, then read the number following it?
Next: i need a matlab program
From: matlab_learner on 11 Apr 2010 23:36 i am tryin to capture the value of a variable at dift points in time (using an index to count) and matlab completely misses that argument (doesn't return a value). here is what i am trying to do: -defined/initialized my variables -start computations -limit for which i am computing the value of velocity is from time 0 = time 20 so i do while time <=20, code runs -now, i need to make velocity plots of velocity vector u,v at dift time levels. the change in time (delta_t) changes for each iteration level so i have code that finds what delta_t should be...so effectively, i know that i am running my code from time 0 to 20...follow so far? so i was doing something like this to capture my velocity u,v at a single time (t =0.0122, although i need to pick velocity at 8 dift times i want to get 1 to work first): -i first defined my counter W outside so W = 0; then during the computations i did: t = t+delta_t %increase time t W = W+1; %increase the counter along with changes in delta_t velocity_plots(W) = t; if velocity_plots == ceil(16.7783) %16.7783 is the last time point i need to store/grab velocity values maxU = u MaxV = v end --end of code.... then when iterations stop i do whos but matlab never returns maxU or MaxV. there is no error but it is missing it completely. any suggestions? tnx.
From: TideMan on 12 Apr 2010 00:10 On Apr 12, 3:36 pm, matlab_learner <cib...(a)gmail.com> wrote: > i am tryin to capture the value of a variable at dift points in time > (using an index to count) and matlab completely misses that argument > (doesn't return a value). > > here is what i am trying to do: > > -defined/initialized my variables > -start computations > -limit for which i am computing the value of velocity is from time 0 = > time 20 so i do while time <=20, code runs > > -now, i need to make velocity plots of velocity vector u,v at dift > time levels. the change in time (delta_t) changes for each iteration > level so i have code that finds what delta_t should be...so > effectively, i know that i am running my code from time 0 to > 20...follow so far? > > so i was doing something like this to capture my velocity u,v at a > single time (t =0.0122, although i need to pick velocity at 8 dift > times i want to get 1 to work first): > -i first defined my counter W outside so W = 0; > then during the computations i did: > t = t+delta_t %increase time t > W = W+1; %increase the counter along with changes in delta_t > velocity_plots(W) = t; > if velocity_plots == ceil(16.7783) %16.7783 is the last time > point i need to store/grab velocity values > maxU = u > MaxV = v > end > --end of code.... > then when iterations stop i do whos > > but matlab never returns maxU or MaxV. there is no error but it is > missing it completely. > > any suggestions? tnx. This: > velocity_plots(W) = t; tells me that velocity_plots is a vector. But here: > if velocity_plots == ceil(16.7783) %16.7783 is the last time will only be true all the values in velocity_plots are identically equal to ceil(16.7783), i.e., 17. So, you've got it wrong on two counts in the if statement: 1. You need to use velocity_plots(W), not velocity_plots 2. You need to express the argument within a tolerance, something like this: if abs(velocity_plots - 16.7783) < 1e-5
From: TideMan on 12 Apr 2010 00:11 On Apr 12, 4:10 pm, TideMan <mul...(a)gmail.com> wrote: > On Apr 12, 3:36 pm, matlab_learner <cib...(a)gmail.com> wrote: > > > > > i am tryin to capture the value of a variable at dift points in time > > (using an index to count) and matlab completely misses that argument > > (doesn't return a value). > > > here is what i am trying to do: > > > -defined/initialized my variables > > -start computations > > -limit for which i am computing the value of velocity is from time 0 = > > time 20 so i do while time <=20, code runs > > > -now, i need to make velocity plots of velocity vector u,v at dift > > time levels. the change in time (delta_t) changes for each iteration > > level so i have code that finds what delta_t should be...so > > effectively, i know that i am running my code from time 0 to > > 20...follow so far? > > > so i was doing something like this to capture my velocity u,v at a > > single time (t =0.0122, although i need to pick velocity at 8 dift > > times i want to get 1 to work first): > > -i first defined my counter W outside so W = 0; > > then during the computations i did: > > t = t+delta_t %increase time t > > W = W+1; %increase the counter along with changes in delta_t > > velocity_plots(W) = t; > > if velocity_plots == ceil(16.7783) %16.7783 is the last time > > point i need to store/grab velocity values > > maxU = u > > MaxV = v > > end > > --end of code.... > > then when iterations stop i do whos > > > but matlab never returns maxU or MaxV. there is no error but it is > > missing it completely. > > > any suggestions? tnx. > > This:> velocity_plots(W) = t; > > tells me that velocity_plots is a vector. > But here:> if velocity_plots == ceil(16.7783) %16.7783 is the last time > > will only be true all the values in velocity_plots are identically > equal to ceil(16.7783), i.e., 17. > > So, you've got it wrong on two counts in the if statement: > 1. You need to use velocity_plots(W), not velocity_plots > 2. You need to express the argument within a tolerance, something > like this: > if abs(velocity_plots - 16.7783) < 1e-5 OOps, that should be: > if abs(velocity_plots(W) - 16.7783) < 1e-5
From: Walter Roberson on 12 Apr 2010 00:16 matlab_learner wrote: > velocity_plots(W) = t; So velocity_plots is an array > if velocity_plots == ceil(16.7783) %16.7783 is the last time And you are comparing the entire array to a particular value. That will evaluate to a vector of logical values. When 'if' is presented with a vector of logical values, it considers the condition to be true only if *all* of the logical values are true. Which will never be the case for your code. Try if velocity_plots(W) == ceil(16.7783)
From: matlab_learner on 12 Apr 2010 12:34
thank you all. i will attempt this tonight. tnx... i just want to grab the values at dift time values. |