Variables not displaying in workspace

조회 수: 5 (최근 30일)
Elise Berning
Elise Berning 2018년 12월 18일
댓글: Stephen23 2018년 12월 18일
Hello,
In MATLAB 2018a version, I am filling in a 3x100 vector that I initialize at the beginning. None of the variables (v,j,heartrate) are showing in the workspace, but am using heartrate(1,:) to plot a graph and that is working successfully. I do not know how I am able to plot this graph if the heartrate matrix is not the workspace. I have posted parts of my code below (it is long, so I have included the necessary parts only). I have tried putting the zeros vector inside and outside the function already. Thank you for your help!
function bpm = MyHeartRateOG(currentheart, restingheart, condition)
heartrate = zeros(3,100);
v = [1:100]
j = [0.8 .95 0.7 0.85 0.85 0.925 0.7 0.85 0.8 0.95 0.85 0.925 0.7 0.85 0.8 0.95 0.85 0.925; 0.8 0.95 0.7 0.85 0.85 0.925 0.07 0.85 0.8 0.95 0.85 0925 0.7 0.85 0.8 0.95 0.33 0.66 ; 0.8 0.95 0.7 0.85 0.85 0.925 0.7 0.85 0.8 0.95 0.85 0.925 0.7 0.85 0.8 0.95 0.33 0.66];%matrix of probabilities
for k = 1:3
heartrate(k,1)= restingheart;
heartrate(k,2)= currentheart;
for i = 2:100
N = rand();
if condition ==1 %Normal Heart
if heartrate(k,i)< heartrate (k,i-1)
(more if statements in between that should fill in the heartrate vector)
plot(v,heartrate(1,:)); %Graph which is being successfully plotted using heartrate matrix
  댓글 수: 1
Stephen23
Stephen23 2018년 12월 18일
"None of the variables (v,j,heartrate) are showing in the workspace..."
But they exist inside the function workspace, which is independent of the base workspace:
To view variables in function's workspace use the debugging tools:

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

답변 (1개)

James Tursa
James Tursa 2018년 12월 18일
편집: James Tursa 2018년 12월 18일
The variables v, j, and heartrate are local variables and only exist inside the function MyHeartRateOG workspace. Once this function returns to the caller, those variables don't exist in the caller workspace. If you want to see them, you will need to pause the code inside the function (click at the left of the line in the editor and it will pause on that line), or you can put these variables in the output argument list to see them in the caller workspace. E.g.,
function [bpm,v,j,heartrate] = MyHeartRateOG(currentheart, restingheart, condition)

카테고리

Help CenterFile Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by