225 views (last 30 days)

Hello all,

im working in simulink with findpeaks and I have the code as below, for the condition if u ~ = 0 it works well, so the else condition is in the condition if u == 0,

but then there is a nan value outside u ~ = 0 so you need to add elseif,

but when I tried with isnan (u) it couldn't detect that he was nan and I wanted to change it to all 0 values

so that there is an error as shown below,

can anyone help me find out where it went wrong thank you very much

function [dist,peak2,locs2] = fcn(u)

locs = zeros(size(u));

pks = zeros(size(u));

if u ~= 0

[pks,locs] = findpeaks(u);

elseif isnan(u)

locs(size(u))= 0;

pks(size(u)) = 0;

else

locs(size(u))= 0;

pks(size(u)) = 0;

end

a = locs(2)- locs(1);

b = pks(1);

c = locs(1);

dist = a;

peak2 = b;

locs2 = c;

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

Start Hunting!
## 35 Comments

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1267580

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1267580

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1267890

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1267890

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1268490

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1268490

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1268510

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1268510

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269045

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269045

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269085

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269085

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269140

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269140

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269145

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269145

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269165

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269165

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269355

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269355

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269360

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269360

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269525

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1269525

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270130

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270130

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270175

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270175

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270395

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270395

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270420

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270420

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270450

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1270450

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1271384

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1271384

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1271389

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1271389

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1272759

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1272759

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1272804

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1272804

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273724

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273724

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273774

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273774

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273784

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273784

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273809

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1273809

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274004

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274004

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274099

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274099

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274104

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274104

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274109

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274109

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274454

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274454

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274969

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1274969

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1275863

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1275863

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1275868

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1275868

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1276353

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1276353

## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1278053

⋮## Direct link to this comment

https://ch.mathworks.com/matlabcentral/answers/718925-how-to-make-nan-turn-into-0-in-array#comment_1278053

Sign in to comment.