Retaining values for a Matrix!

I have a matrix A. A has dimensions (10,100). I also have 10 different text files.Each text file loads 100 binary values.I have written a script which loads a text file,copies all the 100 binary values in A and displays A.I want A to retain all the rows for 10 text file loads serially.I am loading the text files serially i.e I take one text file, load it, copy its data into A,then again replace the previous text file with the new one, run the script again , load new values in A...till all the text files are loaded. How can I achieve this? To save all the previous data in a matrix even after running the same script with new inputs multiple times Help appreciated! Waiting..

2 Commenti

It'll be a lot easier to help if you share your script.
The portion of concern from the script is as follows:
file_contents = readFile('SPAM_SAMPLE1.txt');
% I have 10 different text files. You can also suggest a way where I can read all the 10 files in one run.
% If not I have to rerun this scripts 10 times to gather all the features from all the 10 files.
word_indices = processEmail(file_contents);
features = emailFeatures(word_indices);
% Here I want a matrix which stores the features ( 1 * 100 ) for all
% different text files

Accedi per commentare.

Risposte (1)

Rik
Rik il 25 Nov 2017
The answer is not overwriting the result, but using a cell, or assigning the result of your function to only part of your matrix.
%option1
A=cell(10,1);
for n=1:10
A{n}=logical(rand(1,100));
disp(A{n})
end
%option2
A=false(10,100);
for n=1:10
A(n,:)=logical(rand(1,100));
disp(A(n,:))
end

2 Commenti

I had mentioned in my query that its not a loop that i am running through. I am running the script 10 times with 10 new text files to obtain 100 * 10 new binary values ans store all of them in one matrix. And naturally if I rerun the scripts multiple times, I will end up re declaring my matrix multiple times, which I dont want.
Rik
Rik il 25 Nov 2017
Which is why you need to add a loop. Just save the filenames in an array as well. You want to repeat a script. Matlab has two tools for that: for-loops and while-loops. I guess you could also trick a recursive function to do it, but that is over-complicating it.

Accedi per commentare.

Categorie

Richiesto:

il 24 Nov 2017

Commentato:

Rik
il 25 Nov 2017

Community Treasure Hunt

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

Start Hunting!

Translated by