Modify cell array in multidimensional array depending on number
Afficher commentaires plus anciens
I have a cell array (part of a multidimensional array) going from 0 to 1 in uneven steps. I wish to perform different calculations on this array, depending on if the values are less than, or greater than 0.5. I was trying to achieve this with an if statement, but I'm not sure if this is the correct approach.
for i=1:2
Timestep{i,1} = Radial{i,1}(:,1);
if Timestep{i,1}<0.5
CSA{i,1}(k) = OriginalDiameter-RadialDisp;
k=k+1
end
if Timestep{i,1}>0.5
CSA{i,1}(k) = CrimpedDiameter+RadialDisp;
k=k+1
end
end
3 commentaires
Jos (10584)
le 19 Déc 2017
Why use cell arrays and not simple numeric arrays? Life would be much easier.
Stephen23
le 20 Déc 2017
@Ciara: it is not clear why you need the extra complexity of using cell arrays. Most likely using ordinary numeric arrays would make your code much simpler.
Réponses (1)
Jan
le 20 Déc 2017
0 votes
What should happen for Timestep{i,1}==0.5?
Working with numerical arrays would be easier. Work with cells only, if the elements have different sizes or types. Otherwise (maybe multi-dimensional) numerical arrays are more efficient and convenient. That the data are imported from a file is no good argument for cells.
If your code is correct or not depends on the meaning of k and on what you want as output. The code itself looks valid.
Catégories
En savoir plus sur Multidimensional Arrays 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!