Undefined function 'cosd' for input arguments of type 'logical'

The function should take floating point values and output disk width, but I am getting the error "Undefined function 'cosd' for input arguments of type 'logical'"
.
function R_disk = disk_rad(A)
% function computes radius of respective disk as a function of the points
% Longitude
gridspc = .1;
R_earth = 6371; %radius of the earth in Km
dist_lat = gridspc * R_earth;
dist_lon = R_earth*gridspc*cosd(A);
A_grid = dist_lat*dist_lon;
R_disk = sqrt(A_grid/pi)/110.946;
end

2 件のコメント

John Chilleri
John Chilleri 2017 年 4 月 24 日
編集済み: John Chilleri 2017 年 4 月 24 日
Hello,
This is because your input A is a logical value rather than a double.
For example:
>> A = 1 == 1
A =
1
>> cosd(A)
Undefined function 'cosd' for input arguments of type 'logical'.
>> A = 1
A =
1
>> cosd(A)
ans =
0.999847695156391
You can get around this by putting an
A = double(A);
or
cosd(double(A))
Although A may be logical due to a bug in your earlier code (I would check if I was you).
Hope this helps!
Franklyn Dunbar
Franklyn Dunbar 2017 年 4 月 24 日
perfect, thanks

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInstall Products についてさらに検索

質問済み:

2017 年 4 月 24 日

コメント済み:

2017 年 4 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by