How to call on an object's location in a matrix?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
RB
le 16 Nov 2017
Modifié(e) : Walter Roberson
le 16 Nov 2017
Hello, currently I have a three dimensional array of a particular size. I have a code that fits data to a particular equation. What I want to do is make a for loop that runs this code on each x,y location in the array. The 'data' or inputs for the code will be every number in that specific location in the z direction. Therefore, every array element in location (1,1) and through the depth of the array will be input into the code. This will be run on every x,y location. Then, I want the output of the code to be written to a new 2d array in the correct element location. So after the (1,1) elements are run through the code, the 'answer' of the code will be written to the new array in location (1,1). However, I am not sure how this for loop should be written, or how to call on the particular location that the for loop is being run on so that the output can be written in the corresponding location on the new array. Any help would be greatly appreciated, thank you!
0 commentaires
Réponse acceptée
Walter Roberson
le 16 Nov 2017
Modifié(e) : Walter Roberson
le 16 Nov 2017
Output = cellfun(@YourFunction, num2cell(YourArray, 3))
You might need to use
Output = cellfun(@(V) YourFunction(V(:)), num2cell(YourArray, 3))
as the num2cell part will give you 1 x 1 x size(YourArray,3) vectors.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements 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!