Error message: Undefined function or variable 'divide'.

Hi All,
I am attempting to divide two datasets, but am getting an error message. I am interpreting this (based on other user questions) that MatLab does not know the function 'divide'. Both datasets are the same size (301x1). Each has NaN values at certain points, but I believe I've taken care of them with the 'isnan' function. Any idea what could be causing this error message?
Cheers.
%%79JPC percent CDW
T = 0:0.1:30;
a = isnan(diff);
b = isnan(diff5);
c = divide(a,b);
plot(T,c);

回答 (2 件)

Joe S
Joe S 2017 年 8 月 3 日

0 投票

For element by element division, just use ./ (use of / without the leading period is matrix division, likely not what you want).
Example:
a = magic(3);
b = a./2; %technically period is not needed when dividing by scalar but I use for consistency.
c = a./b
It will handle 'NaN' easily in the answer with a NaN.
a = magic(3);
b = a./2;
b(1) = NaN;
c = a./b
See >> help ./

3 件のコメント

Vince Clementi
Vince Clementi 2017 年 8 月 3 日
I found the './' function online and tried using it. This is what happens when I do:
Undefined operator './' for input arguments of type 'logical'.
Error in PercentCDW (line 80) c = (a./b);
I am not sure what this means.
Joe S
Joe S 2017 年 8 月 3 日
When you use isnan(diffs), the result will be a logical, 1 for YES, 0 for no, for each element in the matrix. You do not need "isnan" prior to division.
Vince Clementi
Vince Clementi 2017 年 8 月 3 日
This worked thanks for explaining!

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

Julie Kraus
Julie Kraus 2017 年 8 月 3 日

0 投票

Divide does not seem to be a function of matlab until 2017a, but mine won't admit it exists either. Any reason you are not doing
c=a./b;
?

3 件のコメント

Vince Clementi
Vince Clementi 2017 年 8 月 3 日
I found the './' function online and tried using it. This is what happens when I do:
Undefined operator './' for input arguments of type 'logical'.
Error in PercentCDW (line 80) c = (a./b);
I am not sure what this means.
Julie Kraus
Julie Kraus 2017 年 8 月 3 日
編集済み: Julie Kraus 2017 年 8 月 3 日
well isnan returns a true/false array with true where the entry was NaN. This is an array of logical arguments. divide wants floating point arguments
Just do
c=diff./diff5;
If you want to remove NaN's after you can do
c(isnan(c))=[];
Vince Clementi
Vince Clementi 2017 年 8 月 3 日
this worked thanks!

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

カテゴリ

タグ

質問済み:

2017 年 8 月 3 日

コメント済み:

2017 年 8 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by