How to solve Reference to non-existent field 'folder'.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a coding like this
folder='D:\\MultiLinierRegression\OutputRd'
fils=dir([folder '\*.txt']); % lists all the files with a .txt extension in myfolder
[~,idx]=sort({fils.name}); % index to load .txt files alphabetically
temp=importdata([fils(idx(1)).folder '\' fils(idx(1)).name]); % read A.txt
Y=temp(:,1); X=temp(:,2:end);
for ii=idx(2:end)
temp=importdata([fils(ii).folder '\' fils(ii).name]);
X =[X temp(:,2:end)];
end
But I got a message like this
Reference to non-existent field 'folder'.
Error in CalcRdAll (line 8)
temp=importdata([fils(idx(1)).folder '\' fils(idx(1)).name]); % read A.txt
Is there any one can help?
0 commentaires
Réponse acceptée
Stephen23
le 3 Nov 2019
Modifié(e) : Stephen23
le 3 Nov 2019
The folder field (and recursive folder searching) was added in R2016b.
As you are not using the recursive folder search you can simply do this:
D = 'D:\\MultiLinierRegression\OutputRd'
S = dir(fullfile(D,'*.txt'));
[~,idx] = sort({S.name}); % index to load .txt files alphabetically
temp = importdata(fullfile(D,S(1).name));
Y = temp(:,1);
X = temp(:,2:end);
for ii = idx(2:end)
temp = importdata(fullfile(D,S(ii).name));
X = [X,temp(:,2:end)];
end
2 commentaires
Stephen23
le 3 Nov 2019
Modifié(e) : Stephen23
le 3 Nov 2019
Apparently your file data do not all have the same sizes. You can avoid this error by importing into a cell array or a structure, e.g.:
D = 'D:\\MultiLinierRegression\OutputRd'
S = dir(fullfile(D,'*.txt'));
for ii = 1:numel(S)
S(ii).data = importdata(fullfile(D,S(ii).name));
end
After the loop you can investigate the sizes, adjust the sizes, and concatenate if possible.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!