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
Kaushik Lakshminarasimhan
2017년 11월 24일
It'll be a lot easier to help if you share your script.
Hrishikesh lele
2017년 11월 25일
답변 (1개)
Rik
2017년 11월 25일
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
Hrishikesh lele
2017년 11월 25일
Rik
2017년 11월 25일
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.
카테고리
도움말 센터 및 File Exchange에서 Numeric Types에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!