Hi!(adsbygoogle = window.adsbygoogle || []).push({});

I have an array that is 1 column by many rows, of which each element represents a time. I want to find variable f at each time, where f is defined as follows:

if t < tp

f=(sin((pi*t)/(2*tp)))^2;

if tp < t < ts

f=(cos((pi*(t-tp))/(2*(ts-tp))))^2;

otherwise f=0

I've tried defining f as above in a .m function file (called elastance), and then using f=arrayfun(elastance,t) to find f at each time, but that doesn't work (It says, "Error in ==> elastance at 5, if t < tp".) Just typing the above function directly into the command window doesn't work either, whether or not I put it in terms of t or (t.).

Does anyone have any suggestions? Thanks!

**Physics Forums - The Fusion of Science and Community**

Dismiss Notice

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Apply if/else if to each element in array in MATLAB

Loading...

Similar Threads - Apply else each | Date |
---|---|

Simple Excel VBA problem; Applying a formula to a column if it contains a number | Jul 8, 2012 |

COMSOL: Problem about optimization applied to a laminar flow | Apr 30, 2012 |

Matlab 3D plot using arrays in if/else | Nov 15, 2011 |

Estimate and apply transfer function to vibration data | Apr 28, 2011 |

How do I apply the pre-tension option to a solid body in Abaqus FEA software? | Feb 14, 2011 |

**Physics Forums - The Fusion of Science and Community**