Hello! I'm trying to save a matrix in the matlab workspace with the function assignin, because that's the only one I know that does this, but the problem is that I don't know if I can manipulate it in order to not overwrite the data I acquire in which loop.
So I'm using this line of code:
assignin('base', varName, captureData);
But the matrix it generates only has the last second of data it captures (each loop is one second) and I need it to save all of the data it gets. I can save it to a txt file, which I'm already doing. But I want to manipulate the generated matrix so I really need the data to be inside of matlab workspace (I'm acquiring data in real time).
Would really appreciate some help, please keep in mind I'm very new to matlab.

댓글 수: 2

Rik
Rik 2021년 7월 9일
Why are you using assignin instead of using functions (or even classes, if you want more persistence)?
Teresa Carneiro
Teresa Carneiro 2021년 7월 9일
Okay so I'm actually using this 4 functions https://www.mathworks.com/help/daq/software-analog-triggered-data-capture.html and the main one, softwareAnalogTriggerCapture, calls the function dataCapture. Inside of the dataCapture function there is this line of code that creates this matrix in the matlab workspace. I don't know how to do it in other way.

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

 채택된 답변

Matt J
Matt J 2021년 7월 9일
편집: Matt J 2021년 7월 9일

1 개 추천

Do not return a result to the base workspace in each pass through the loop. At the completion of your loop, you should have accumulated a vector containing all the results. You should pass that back to the base workspace.

댓글 수: 6

Teresa Carneiro
Teresa Carneiro 2021년 7월 9일
It's not actually a loop, it's a group of functions (please see my comment to Rik above), and the main one calls this function a lot of times, and I think that everytime it calls it the assignin line of code just overwrites the data that was already there. My goals is to get at least 30 seconds worth of data, which is 30000 rows, because I'm acquiring at a 1000samples/sec rate. After the first 30 seconds I need this matriz to delete the first 1000 rows (first second), move to rows 1:29 and register the new second (second 31 in this case) in the new space available after moving the matrix to start at row 1
Matt J
Matt J 2021년 7월 9일
편집: Matt J 2021년 7월 9일
What a mess! Well, what you might try is to modify the code as below. You will first have to set varName=[] in the base workspace before you run the code.
previousData=evalin('base',varName);
assignin('base', varName, [previousData,{captureData}]);
Thank you!! It worked using
previousData=evalin('base',varName);
assignin('base', varName, [previousData;captureData]);
So I could get it all in the same matrix :)
Teresa Carneiro
Teresa Carneiro 2021년 7월 9일
If you find a way for it to restart the variable when I run the main function again that would be great.
Teresa Carneiro
Teresa Carneiro 2021년 7월 9일
Okay I just realized that the variable is only saved after I run the code, I needed to be able to change values of the matrix while the code was running. Is there anyway?
If you find a way for it to restart the variable when I run the main function again that would be great.
persistent cumulativeData
cumulativeData=[cumulativeData;captureData];
assignin('base', varName, cumulativeData);
Okay I just realized that the variable is only saved after I run the code, I needed to be able to change values of the matrix while the code was running.
Not sure i understand what you wrote here, but with the above, you can insert any changes you wish to cumulativeData before the call to assignin.

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

추가 답변 (0개)

카테고리

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

질문:

2021년 7월 9일

댓글:

2021년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by