Hi everyone:
Here is my issue...
I am inputting numerous text files inside of a FOR loop in order to pull two particular columns out, one with all characters and one with numbers (double). The code that I have so far, copied below, works as desired. Note that I set "numsvns" as only one entry for debugging.
numsvns = [61]; %only one number for debugging purposes
home_path = path;
for i = 1:length(numsvns)
svn1 = numsvns(i);
svn = int2str(svn1);
directory = strcat('output/sv',svn);
path(home_path,directory)
fid = fopen('groundVisibilityEvents.txt');
eval(['gve' svn ' = textscan(fid,''%s %s %f %f %s %s %s %f'');'])
eval(['site' svn ' = gve' svn '{1};'])
eval(['duration' svn ' = gve' svn '{8};'])
end
This creates two variables of importance, one called "site61" with ASCII characters and one called "duration61" with the double times. Of course, the variables have the 61 appendix since I set "numsvns" = 61 alone.
My next step is to search through "'duration' svn" (in this case, "duration61") in order to find the indices of zero terms. The following works great, as expected:
index = find(duration61==0);
However, I cannot figure out how to generalize this inside of my FOR loop. The following commands don't work, because the "find" function interprets the "duration61" as a character string rather than array:
index = find(['duration' svn]==0);
or, eval(find(['duration' svn]==0));
or, eval(find(['duration' str2num(svn)]==0));
or, abc='duration61'; find(abc==0);
etc.
Is there a way to turn a string into a variable? I thought that "eval" should have done that, but no luck. Otherwise, how do I generalize the "find" command to work with a generic "duration##", where the ## is specified in the loop?
Thank you,
Jeff
1 Comment
Andrew Newell (view profile)
Direct link to this comment
https://ch.mathworks.com/matlabcentral/answers/11981-help-with-find-possibly-inside-of-eval#comment_26470
Sign in to comment.