Effacer les filtres
Effacer les filtres

function assignin overwrites my data

3 vues (au cours des 30 derniers jours)
Teresa Carneiro
Teresa Carneiro le 9 Juil 2021
Commenté : Matt J le 9 Juil 2021
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 commentaires
Rik
Rik le 9 Juil 2021
Why are you using assignin instead of using functions (or even classes, if you want more persistence)?
Teresa Carneiro
Teresa Carneiro le 9 Juil 2021
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.

Connectez-vous pour commenter.

Réponse acceptée

Matt J
Matt J le 9 Juil 2021
Modifié(e) : Matt J le 9 Juil 2021
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 commentaires
Teresa Carneiro
Teresa Carneiro le 9 Juil 2021
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?
Matt J
Matt J le 9 Juil 2021
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by