Home Unpacking a vector into k variables
Reply: 0

Unpacking a vector into k variables

user1185
1#
user1185 Published in May 23, 2018, 4:47 pm

I'm learning matlab and trying to implement small angle approximation using vectorisation. This is the formula I'm trying to implement:

I'm implementing this for 3 angles: pi / 100, pi / 10 and pi / 6. I've come up with this so far:

x = [pi / 100, pi / 10, pi / 6];
y = sin(x);
e = (y - x) ./ y;

This works fine. Now, I want to unpack the result into 3 variables. I know I can do this:

RelativeError100 = e(1);
RelativeError10 = e(2);
RelativeError6 = e(end);

But coming from a python background, this seems a bit clunky to me. So I tried this:

[RelativeError100, RelativeError10, RelativeError6] = e

Which errors out, giving Too many output arguments.. So, I did a little research, and came across this which suggests

[RelativeError100, RelativeError10, RelativeError6] = e{:}

Which throws a Cell contents reference from a non-cell array object..

What am I missing, and how can I get this to work? Or is it just not possible with matlab?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.419723 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO