Modify cell array in multidimensional array depending on number

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

Why use cell arrays and not simple numeric arrays? Life would be much easier.
Ciara's "Answer" moved here:
I'm reading in data from columns in a txt file, so this is why I assign in a multidimensional array
@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.

Connectez-vous pour commenter.

Réponses (1)

Jan
Jan le 20 Déc 2017
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

Tags

Question posée :

le 19 Déc 2017

Commenté :

le 20 Déc 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by