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 Kommentare

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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jan
Jan am 20 Dez. 2017

0 Stimmen

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.

Kategorien

Tags

Gefragt:

am 19 Dez. 2017

Kommentiert:

am 20 Dez. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by