Modify cell array in multidimensional array depending on number
Ältere Kommentare anzeigen
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
Jos (10584)
am 19 Dez. 2017
Why use cell arrays and not simple numeric arrays? Life would be much easier.
Stephen23
am 20 Dez. 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.
Antworten (1)
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
Mehr zu Multidimensional Arrays finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!