How to call function on each element in structure
Show older comments
Hi,
I am using the function rdir to list the files names ' forces.dat ' in the current directory. It generates a structure D similar to the one returned by the built-in dir command.
The goal is then to go over every name field of the structure D (that includes the relative path as well as the name to the file that was found) and call the function importForces to go over each element in that field (you will find attached the corresponding function importForces.m and script forcesData.m). Now I am having trouble assigning this function to each element in a recursive way, the typical errors I get are :
Error using fopen
First input must be a file name of type char, or a file identifier of type double.
Error in importForces (line 26)
fileID = fopen(filename,'r');
or
Error using textscan
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in importForces (line 29)
dataArray = textscan(fileID, formatSpec, endRow(1)-startRow(1)+1, 'Delimiter', delimiter, 'MultipleDelimsAsOne', true, 'EmptyValue'
,NaN,'HeaderLines', startRow(1)-1, 'ReturnOnError', false);
I tried many things : converting to table, to cell array, etc, but I still can't wrap my head around how to use that function to go over ever element considering the STRING of characters only.
Any help would be much appreciated!
Thanks, - Farah
Accepted Answer
More Answers (0)
Categories
Find more on Structures 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!