I am running a while loop to take the average value of a selcted portion of a matrix. My loop selects a fixed amount of rows and sweeps through columns via the while loop. I want to plot these points as a line vs my upper bound(yU), but I can only seem to get a scatter plot. Does anyone know how to do this?
function [avg] = sweep(mat,xL,xU,yL,yU,ystep,ymax)
while yU < ymax
selmat = mat(xL:xU,yL:yU);
avg = mean(mean(selmat(~isnan(selmat))));
plot(yU,avg,'-x')
hold on
yL = yL + ystep;
yU = yU + ystep;
end
end

 채택된 답변

Star Strider
Star Strider 2019년 4월 30일

0 개 추천

I have no idea what the arguments to your function would be, so I can’t run your code.
Note that this assumes that the calculated values for each element of ‘avg’ and ‘yU’ are scalars.
Try this:
kount = 0;
while yU < ymax
kount = kount + 1;
selmat = mat(xL:xU,yL:yU);
avg(kount) = mean(mean(selmat(~isnan(selmat))));
yL = yL + ystep;
yU = yU + ystep;
yUv(kount) = yU;
end
figure
plot(yUv,avg,'-x')
Make appropriate changes to get the result you want.

댓글 수: 2

Josh Hanner
Josh Hanner 2019년 4월 30일
Worked out perfectly! Thanks!
I am running the function within a script that computes the average spl(sound pressure level in dB) for a 3x3 control room. The control room can vary in location anywhere on a 15x15 manufacturing floor, and it is up to me to pick an optimal location where the average spl is at a minimum.
3-d spl.PNG
I am basically sweeping a 3x3 grid across this 3-d plot. I'm sure there is a better way to do it, but thanks for the help!
Star Strider
Star Strider 2019년 4월 30일
As always, my pleasure!
There may be some Image Processing Toolbox functions, such as imfilt, that could be apppropriate. It depends on what you want to do.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

2019년 4월 30일

댓글:

2019년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by