Using the find function in a loop
5 views (last 30 days)
Show older comments
I wrote this script to import multiple files. Now I try tofind the variables. Every file has a different amount of rows. I like to use the find function to find my variables. Every time I get an error. Can someone help me?
1 Comment
KSSV
on 9 Apr 2018
What error you get? Which line you are getting the error? What file we have to select to run the code?
Accepted Answer
Guillaume
on 9 Apr 2018
The immediate cause for the error is simple, you already have a variable called datarecords and it's not a cell array. Since none of the variables you're using in your loop are predeclared you're either reusing whatever exists or creating them in the first step of the loop.
datarecords = {};
mydata = {};
before the loop would fix that error.
However the rest of the code doesn't make much sense. I very much doubt that importdata is going to return a structure when loading a text file, so your mydata{k}.textdata is probably an error as well.
k is either 1 or 4, never any other value, so it's unclear why it's used as an index. And if its only purpose is to break out of the loop then:
while true
%...
if strcmp(Answer, 'No')
break;
end
end
is better.
I think that rather than fixing that script, you'd be better off explaining better what you want to do and showing an example of the text file you want to load and telling us which part of that file you're interested in.
More Answers (1)
See Also
Categories
Find more on Manage Products in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!