I have a for loop that gives results that are constantly updating
x= 'A'
x= 'B'
x= 'C'
But I would like to convert that into x= {'A', 'B', 'C'}
Any Suggestions?

 채택된 답변

Thorsten
Thorsten 2016년 7월 1일

0 개 추천

clear x
x{1} = 'A';
x{end+2} = 'B';
x{end+3} = 'C';
and so on

댓글 수: 4

chlor thanks
chlor thanks 2016년 7월 1일
but I have hundred of these and is there a way I can do this in one command?
No. There is no way to give a command along the lines of "collect all of the values that were generated for X into a cell array. You need to put them into the cell array at the time you generate them (or at least before X changes). For example you might have
for K = 1 : 50
r = rand();
if r < 0.3
X = 'A';
elseif r < 0.38
X = 'B';
elseif r < 0.92
X = 'C';
else
X = 'D';
end
X_vals{K} = X;
end
chlor thanks
chlor thanks 2016년 7월 5일
편집: chlor thanks 2016년 7월 5일
This is what I have been working on, I am trying to make the last line AllExcel into a cell array but it did not come out right... I have a result of AllExcel that is constantly updating and I am not really sure how to fix it. Will you able to help me on this? Much appreciated!
for k = 1 : numFolders
SubFolder = listOfFolderNames{k};
filePattern = fullfile(SubFolder, '*.xls*');
ExcelFiles = dir(filePattern);
if ~isempty(ExcelFiles)
for k2 = 1 : length(ExcelFiles)
AllExcel={ExcelFiles(k2).name}
end
end
end
numfiles = 0;
for k = 1 : numFolders
SubFolder = listOfFolderNames{k};
filePattern = fullfile(SubFolder, '*.xls*');
ExcelFiles = dir(filePattern);
if ~isempty(ExcelFiles)
for k2 = 1 : length(ExcelFiles)
numfiles = numfiles + 1;
AllExcel{numfiles} = fullfile(SubFolder, ExcelFiles(k2).name);
end
end
end
However, what I would do instead is look in the File Exchange for https://www.mathworks.com/matlabcentral/fileexchange/19550-recursive-directory-listing or https://www.mathworks.com/matlabcentral/fileexchange/32226-recursive-directory-listing-enhanced-rdir

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

추가 답변 (0개)

카테고리

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

질문:

2016년 7월 1일

댓글:

2016년 7월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by