I need to receive one row vector do some math on it and return two row vectors, I'm getting an error regarding parentheses. What's wrong?

1 view (last 30 days)
function (R1, R2) = light_speed(I) x = size(I); R1[1:1:x] = I[1:1:x]*1.609; R2[1:1:x] = I[1:1:x]/300000; end

Accepted Answer

DJ V
DJ V on 9 Nov 2016
I got it to work...

More Answers (1)

Steven Lord
Steven Lord on 9 Nov 2016
Indexing into matrices in MATLAB uses parentheses, not square brackets.
Defining a function that has multiple outputs requires the output arguments in the definition to be enclosed in square brackets, not parentheses.
The colon operator may not behave the way you think for a nonscalar input, like the output of the size function with one input. You probably want to use numel instead of size.
I'm guessing that you're new to MATLAB. If that is the case I highly recommend going through the Getting Started section of the documentation and/or MATLAB Academy. Find the equivalent of this page in your installed documentation and read through the tutorials and/or complete the interactive MATLAB Academy tutorial.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!