Matlab coding and workspace

How do I update the value stored in variable in workspace in every iteration while an infinite FOR loop is running in my matlab script?

2 件のコメント

madhan ravi
madhan ravi 2019 年 6 月 13 日
Why is the for loop infinite? Why not use a while loop nor a condition (break) statement to suffice the loop?
Nits
Nits 2019 年 6 月 13 日
Even if I use the while loop, how am I going to get my objective of flashing variable along with value in workspace on every iteration? Because once break command is executed, I can’t go back to the loop again infinite times#live data streaming from camera.

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

回答 (1 件)

KSSV
KSSV 2019 年 6 月 13 日

0 投票

A = zeros(100,1) ; % initilaize
for i = 1:100
A(i) = rand ; % update the value in loop
end

5 件のコメント

Nits
Nits 2019 年 6 月 13 日
When I am running this code snippet for i=1:inf, then the workspace is not populating with variable and value stored in it on each iteration and waiting for loop to end so as to flash the variable in workspace.
KSSV
KSSV 2019 年 6 月 13 日
First inf would be a very huge number. Show us your code and tell what you want.
Nits
Nits 2019 年 6 月 13 日
Please find my matlab code below. Here I am trying to get position coordinates of an object in every iteration from camera software. The problem with this code is that I am not able to flash the x,y,z i.e. position coordinates on every iteration rather publishing it once the loop terminates. Since it is live data streaming, I cannot restrict the iteation or loop count here.
Thanks for your time!!
##Code
% function NatNetPollingSample
fprintf( 'NatNet Polling Sample Start\n' )
% create an instance of the natnet client class
fprintf( 'Creating natnet class object\n' )
natnetclient = natnet;
% connect the client to the server (multicast over local loopback) -
% modify for your network
fprintf( 'Connecting to the server\n' )
natnetclient.HostIP = '127.0.0.1';
natnetclient.ClientIP = '127.0.0.1';
natnetclient.ConnectionType = 'Multicast';
natnetclient.connect;
if ( natnetclient.IsConnected == 0 )
fprintf( 'Client failed to connect\n' )
fprintf( '\tMake sure the host is connected to the network\n' )
fprintf( '\tand that the host and client IP addresses are correct\n\n' )
return
end
% get the asset descriptions for the asset names
model = natnetclient.getModelDescription;
if ( model.RigidBodyCount < 1 )
return
end
% Poll for the rigid body data a regular intervals (~1 sec) for 10 sec.
fprintf( '\nPrinting rigid body frame data approximately every second for 10 seconds...\n\n' )
a = [];
c = [];
d = [];
for idx = 1 : 30
java.lang.Thread.sleep( 996 );
data = natnetclient.getFrame; % method to get current frame
if (isempty(data.RigidBody(1)))
fprintf( '\tPacket is empty/stale\n' )
fprintf( '\tMake sure the server is in Live mode or playing in playback\n\n')
return
end
fprintf( 'Frame:%6d ' , data.Frame )
fprintf( 'Time:%0.2f\n' , data.Timestamp )
for i = 1:model.RigidBodyCount
fprintf( 'Name:"%s" ', model.RigidBody( i ).Name )
a=[a data.RigidBody( i ).x * 1000];
assignin('base','var1',a)
fprintf( 'X:%0.1fmm ', data.RigidBody( i ).x * 1000 )
end
for i = 1:model.RigidBodyCount
fprintf( 'Name:"%s" ', model.RigidBody( i ).Name )
c=[c data.RigidBody( i ).y * 1000];
assignin('base','var2',c)
fprintf( 'Y:%0.1fmm ', data.RigidBody( i ).y * 1000 )
end
for i = 1:model.RigidBodyCount
fprintf( 'Name:"%s" ', model.RigidBody( i ).Name )
d=[d data.RigidBody( i ).z * 1000];
assignin('base','var3',d)
fprintf( 'Z:%0.1fmm\n', data.RigidBody( i ).z * 1000 )
end
end
disp('NatNet Polling Sample End' )
Walter Roberson
Walter Roberson 2019 年 6 月 13 日
I do not understand what you mean by "flash" in this situation ?
Nits
Nits 2019 年 6 月 13 日
I am sorry about that. By flash I mean to publish the variables in workspace.

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

カテゴリ

ヘルプ センター および File ExchangePerformance and Memory についてさらに検索

製品

リリース

R2017b

タグ

質問済み:

2019 年 6 月 13 日

コメント済み:

2019 年 6 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by