How to construct a script to create a vector of variables from many different scripts

3 Ansichten (letzte 30 Tage)
At the moment I have a script for each set of data I am working with (a bad way of doing things I am sure), which performs the same calculations on each data set.
I want to write a script which stores the same variable from each script into a vector. However, when I run the following script, it obtains each variable value fine, but when storing it in the vector, the preceding variable value is set to 0, so I end up with a vector of zeros with only the last value non-zero.
Here is what I've attempted to far, trying to construct a vector of data file lengths:
Script1
metaCSstat(1)=filelength;
Script2
metaCSstat(2)=filelength;
Script3
metaCSstat(3)=filelength;
I end up with a vector[0 0 filelength(from Script3)]
Sorry if this explanation is a little convoluted, I hope it is understandable.
Many thanks for any help with this matter

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 5 Aug. 2012
Bearbeitet: Azzi Abdelmalek am 12 Sep. 2012
check your scripts, is there any "clear" insstruction; or is your variable "metaCSstat" used in those scripts? I notice also in your example you are using two differtents variables:
metastat(1)=filelength;
metaCSstat(2)=filelength;
  1 Kommentar
Josh
Josh am 5 Aug. 2012
The different variable names was a typo, now corrected.
I did indeed use a "clear" instruction which I have removed from all individual scripts. Thanks for your help

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Oleg Komarov
Oleg Komarov am 5 Aug. 2012
Bearbeitet: Oleg Komarov am 5 Aug. 2012
It's hard to say without knowing what you do in the scripts, but two things:
  • metastat is not metaCSstat
  • If you are using clear(), especially clear all in the scripts that would explain.
  1 Kommentar
Josh
Josh am 5 Aug. 2012
To the first point, that was a typo which I have no corrected.
To the second point, I do indeed clear at the beginning of each of my scripts.
The scripts themselves just do simple calculations, such as working out frequencies of certain events within the data sets.
How can I get around the fact that I start all my individual scripts with clear all?
What I've been doing up to now was to manually run each script individually and copy the desired variable values to to excel or similar. This is time consuming and I wanted to be able to obtain the desired variable values from all scripts at once for easier comparison.

Melden Sie sich an, um zu kommentieren.


Josh
Josh am 5 Aug. 2012
Oops!
I didn't mean to accept your answers just yet, as when I removed the clear instruction from the beginning of each of my individual data-managing scripts I end up getting errors when running my meta script.
I can't see a way around this problem. Is there are way to clear out the variables used in each individual data-managing script but still create a vector which stores the values of a particular variable from each of these scripts, while keeping the clear instruction in each individual data-managing script?

Kategorien

Mehr zu Historical Contests finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by