From: Nehal on 7 Aug 2010 04:45 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <fd68a9fa-ab00-438a-b483-320ed825190a(a)d8g2000yqf.googlegroups.com>... > On Aug 6, 11:55 pm, "Nehal " <arnab...(a)yahoo.com> wrote: > > a little progress... now there shows a variable... but it's not "G".. the variable it shows: "ans". > > I was expecting "G". > > can you help me..? > ----------------------------------------------------- > If you just call test, that's what it will say since you didn't stuff > the return value into any array. If you had said > g1 = test() then it would have said g1 = that number instead of ans. > ans is short for "answer" and is the default name given to return > values when you don't accept them into any variable, but simply just > call the function. Make sense? yes.. I understood. But I created an array of return values. Still, it doesn't work. function G = test tifFiles = dir('*.tif'); %takes all the images from the folder Sample for k = 1:length(tifFiles) %the loop will continue for the number of images filename = tifFiles(k).name; % takes the an image and it's file name I = imread(filename); % reads the image to I G(:,k)= I(:); % reshapes the matrix into 1 column end end I am suppose to get a variable "G" in my workspace. But it is still not showing. Why..?
From: ImageAnalyst on 7 Aug 2010 09:10 On Aug 7, 4:45 am, "Nehal " <arnab...(a)yahoo.com> wrote: > yes.. I understood. But I created an array of return values. Still, it doesn't work. > I am suppose to get a variable "G" in my workspace. But it is still not showing. Why..? ----------------------------------------------------------------------- You think you understand but you don't. First of all, your code won't work unless all images are the same size, but let's assume they are. Now let's say you have two images and do >> test you'll see: ans = 167 167 167 167 167 167 etc. Now let's say you do >> g1=test You'll see g1 = 167 167 167 167 167 167 etc. Note there's no G in the base workspace because I didn't accpet the output into any variable called G. Also observe that when I didn't accept it into ANY variable, it called it "ans." Now let's do >> G = test G = 167 167 167 167 167 167 etc. NOW, we DO have a variable called G in the base workspace. By coincidence I called it G, same name as the variable internal to the function but they're different G's in different workspaces/scopes. Even when I was not accepting the output into any variable or a variable called g1, there was a variable G created BUT it existed (had scope in) ONLY the function called "test." If you put a breakpoint INSIDE that function near the very end, you will in fact see a G variable. However, once test existed, that G variable went out of scope and was probably destroyed along with all the other variables internal to it (i.e., I, k, filename, & tiffFiles). The G that lived in that function never makes it out of that function, it basically just transfers it's values into the variable that you've set up to accept all the values, in other words it transfers the values into the variable on the left hand side of your call statement, such as g1, G, or whatever name you choose to use. If you don't use a variable, then it just calls it "ans." NOW, does it make sense?
From: Nehal on 7 Aug 2010 12:53 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <e270b806-50a7-4c7e-98e2-c4f7b8595568(a)s9g2000yqd.googlegroups.com>... > On Aug 7, 4:45 am, "Nehal " <arnab...(a)yahoo.com> wrote: > > yes.. I understood. But I created an array of return values. Still, it doesn't work. > > I am suppose to get a variable "G" in my workspace. But it is still not showing. Why..? > ----------------------------------------------------------------------- > You think you understand but you don't. First of all, your code won't > work unless all images are the same size, but let's assume they are. > Now let's say you have two images and do > > > However, once test existed, that G variable went out of scope and was > probably destroyed along with all the other variables internal to it > (i.e., I, k, filename, & tiffFiles). The G that lived in that > function never makes it out of that function, it basically just > transfers it's values into the variable that you've set up to accept > all the values, in other words it transfers the values into the > variable on the left hand side of your call statement, such as g1, G, > or whatever name you choose to use. If you don't use a variable, then > it just calls it "ans." NOW, does it make sense? 1st of all... all the images are the same size... 2nd... I have the idea that some how "G" (G = test) in my code is getting destroyed.. I tried to come up with a solution.. but wasn't able to.
From: James Tursa on 7 Aug 2010 12:57 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <e270b806-50a7-4c7e-98e2-c4f7b8595568(a)s9g2000yqd.googlegroups.com>... > > However, once test existed, that G variable went out of scope and was > probably destroyed along with all the other variables internal to it > (i.e., I, k, filename, & tiffFiles). The G that lived in that > function never makes it out of that function, it basically just > transfers it's values into the variable that you've set up to accept > all the values, in other words it transfers the values into the > variable on the left hand side of your call statement, such as g1, G, > or whatever name you choose to use. To clarify a bit, a statement such as: X = test(stuff) will cause the the data area of the G in the test workspace to be directly attached to the data area of X in the calling workspace. There will be no data copy involved so you don't have to worry about inefficiencies in that step of the process. James Tursa
From: ImageAnalyst on 7 Aug 2010 13:01 On Aug 7, 12:53 pm, "Nehal " <arnab...(a)yahoo.com> wrote: > I have the idea that some how "G" (G = test) in my code is getting destroyed.. I tried to come up with a solution.. but wasn't able to. ---------------------------------------------------------------- Well then it's very difficult, or impossible, to help you further. Can you search through all your code and print here every single place where the word "test" appears? Then we should be able to see if "test" is even being called, and it if is, what variable (if any) is taking the returned results.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Saving a portion of pathname as a string? Next: Decimation Problem |