필터 지우기
필터 지우기

I want to access the variable outside the loop or want to change the variables value in loop but in every iteration

조회 수: 7 (최근 30일)
I am getting real time data in every 5 seconds (with pause) with a while loop and make varibales to store that data which come from amazon s3 service . How can I use the current data outside the loop and proceed to do computation with the most current data ? When the loop is running I can not do anything and not get the letest value of the variables in base workspace until it is finished.. And I need to create infinite loop to continuously get the data.
Here I got the variables in baseworkspace when I stop the script to running but I want it in every 5 seconds when when one iteration is finished of while.
while 1
options = weboptions("ContentType", "text");
jsonData = webread('https://amazon-bucket.s3.amazonaws.com/Testdata', options);
% Convert the JSON data to a character vector
jsonDataChar = char(jsonData);
% Parse the JSON data into a MATLAB structure
dataRcv = jsondecode(jsonDataChar);
% Extract the desired values
V = dataRcv.V;
Hydro = dataRcv.Hydro;
Lvl = dataRcv.Lvl; % and other variables
disp('Running....');
pause(5)
end
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 12월 8일
What computation do you have to do?
You can define a function and call it using the data for each iteration of the while loop.
Dhenish
Dhenish 2023년 12월 11일
I want to use varibables for Simulink so as per my knowledge I can use varibables which are store in base workspace.
So I want to store all the variable in base workspace and that data are changing in every 5 seconds so I used while loop to run the script in every 5 seconds. But the problem is when the loop is running I can not do anything and not get the letest value of the variables in base workspace.
Function for what ??

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

채택된 답변

Florian Bidaud
Florian Bidaud 2023년 12월 8일
편집: Florian Bidaud 2023년 12월 8일
One solution could be to save it in a mat file at each step, then you have full access to it with a parfeval or any parallel computing tool for example.
  댓글 수: 2
Dhenish
Dhenish 2023년 12월 11일
For that purpose can I save file inside the while loop ?? With this line of code ??
save result.mat dataRcv -mat;
Here I have a json structure inside the dataRcv variable and all the variables which I need that all are in dataRcv. So If I got the dataRcv then I computation what I want.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 JSON Format에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by