How to apply multiple parameters function on all the matrices in the folder?
Afficher commentaires plus anciens
A=randperm(16);
A=reshape(A,4,4);
function [B]=fun(A,a,b,c)
B= a.*A+b.*A+c.*A
end
vals = [1, 2,3
6,1,4
7,3,5] ;
[m,n] =size(vals) ;
B = zeros(4,4,m) ;
for i = 1:m
B(:,:,i)=fun(A,vals(i,1),vals(i,2),vals(i,3)) ;
end
The above code works perfectly for single A,
I want to apply the above on set of matrices stored in a foder
l have tried the following but it stored result only for single A
srcFiles = dir(...); % the folder in which matrices exists
for i = 1 : length(srcFiles)
filename = strcat('...',srcFiles(i).name);
I = %reading(filename);
vals = [1, 2,3
6,1,4
7,3,5] ;
[m,n] =size(vals) ;
B = zeros(4,4,m) ;
for j = 1:m
B(:,:,j)=fun(I,vals(j,1),vals(j,2),vals(j,3)) ;
% and want to save all the new B's .
end
end
3 commentaires
Awais Saeed
le 16 Sep 2021
Do not know what your actual problem is but your loop structure does not seem OK. Let's say you have 2 files. You read file1 and after some operations you get 3D B array. But when you do the same process again for file2, you are overwriting B array. Do not you want B array for all files?
Ammy
le 16 Sep 2021
Modifié(e) : Image Analyst
le 16 Sep 2021
Awais Saeed
le 16 Sep 2021
Modifié(e) : Awais Saeed
le 16 Sep 2021
To store results for all matrices, use cell arrays. Something like this
for j = 1:1:m
B = fun(FileLoaded,vals(j,1),vals(j,2),vals(j,3));
Results{i,j} = B;
end
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!