Variables not displaying in workspace

2 次查看(过去 30 天)
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