How do I find sin of a cell variable (el)?

Assuming el is cell variable with a matrix of 30 X 3300 being rows and colums.
for PRN =1:30
for t = 1:3300
M_d(PRN,t)= 1/(sin(el(PRN,t))+(0.00143/tan(el(PRN, t))+0.0445));
M_w(PRN, t)=1/(sin(el)+(0.00035/tan(el)+0.017));
end
end
The error i had.
Check for incorrect argument data type or missing argument in call to function 'sin'.

5 Comments

You used the wrong type of indexing. Indexing cell arrays is very simple:
  • () parentheses refers to the cells themselves.
  • {} curly braces refers to the cell content.
If you want to refer to the cell content, then you need to use curly braces.
I have done so, but I keep getting an undefined error whic is quite unrelated with the other.
Thanks anyway
for t = 1:3316
M_d(PRN,t)= 1/sin{el{PRN,t}} + (0.00143/tan{el{PRN, t}}+0.0445);
M_w(PRN,t)=1/(sin{el{PRN,t}}+(0.00035/tan{el{PRN, t}}+0.017));
end
Undefined variable sin.
Error in Troposphere (line 29)
M_d(PRN,t)= 1/sin{el{PRN,t}} + (0.00143/tan{el{PRN, t}}+0.0445);
SIN is a function. Functions in MATLAB are always called using parentheses, not curly braces like you used.
M_d(PRN,t)= 1/sin{el{PRN,t}} + (0.00143/tan{el{PRN, t}}+0.0445);
% ^ ^ ^ ^ should be parentheses
Oh, it worked. Thanks for pointing that out.
Could you confirm that each entry in the cell is a numeric scalar? Your code will fail otherwise.
If it is a numeric scalar then use cell2mat and simple vectorized numeric calculations. Remember to switch from / to ./

Sign in to comment.

Answers (1)

If the value is stores in a cell, then you should write
el{PRN,t}
in order to extract the value as a double.

Categories

Asked:

on 5 May 2022

Commented:

on 6 May 2022

Community Treasure Hunt

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

Start Hunting!