Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.8K Views
|
5 Replies
|
1 Total Like
View groups...
Share
Share this post:

Using IF in FOR loop

Posted 10 years ago

What should be changed in the following code?

bbs = {40, 80, 125, 160, 200, 250, 320, 400, 500, 640, 800, 1000, 
  1250, 1600, 2000, 2500, 3200, 4000, 6400}
For[i = 1, i < 6401, i++, If[MemberQ[i, bbs], Print[
   zx = Import["i.tiff", "Data"];
   totnoise = Total[Flatten[zx]]], 1]]
POSTED BY: fary farfar
5 Replies

I see your bug... (aside from correcting MemberQ[i,bbs] to MemberQ[bbs,i]). (Again, I really didn;'t read your code in detail--sorry!) This is that your

Import["i.tiff", "Data"]

needs to be

Import[ToString[i]<>".tiff", "Data"]

in your original "i.tiff" this is just a string. The ienter code here in it is just the string character and has nothing to do with your index in your For loop.

POSTED BY: David Reiss
Posted 10 years ago

Thanks, everything with the directory is fine and the files exist :) Anything wrong with the code?

POSTED BY: fary farfar

I will admit that I did not investigate your code much more than noting that you needed to correct the MemberQ[bbs,i] call. (See http://reference.wolfram.com/language/ref/MemberQ.html to review the correct form of the arguments.)

So your next step is to see if the Import function is seeing the files you are asking it to import. Take one such file, say 40.tiff, and try importing it simply by calling

Import["40.tiff"]

if this returns $Failed then Import has not found the file. Why might this happen? When you don't give a full file path to Import, Import is looking for the file in the directory returned by

Directory[]

So you now have two possibilities (assuming that the file 40.tiff actually exists!). One is to change the value the default directory using SetDirectory. The other is to provide the full file path of the file you want to Import to the Import function.

POSTED BY: David Reiss
Posted 10 years ago

Thanks, but already tried it, Says "Import::nffil: File not found during Import" and "Nonatomic expression expected at position 1 in Flatten[$Failed]".

POSTED BY: fary farfar

MemberQ[bbs,i]

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard