concatenating string variable names and passing on values of a matrix in a for loop
이전 댓글 표시
Hi there,
I have many files, for each file I create variable names with part of the filename (using for loop and counter the filecounter) and then, I pass on to them the values of a matrix (AWFR) I create for each iteration, using eval()
The problem is that I want to concatenate all these column - vector variables into one large column vector, without having to type the names manually all over again, after these are saved in the workspace.
I managed to create a matrix containing all the names of the variables (AWFRallthenames), but I couldn't pass on the values with eval([AWFRallthenames(filecounter,:),'=AWFR']).
Is there any other way and why the above does not work? I am attaching a part of the code if that helps!!
Any help appreciated! Thank you
for filecounter=1:2%length(FileList)
.......
datehour=BasicName(end-12:end)
onoma1='AWFR'
onoma2=datehour
AWFRname=horzcat(onoma1,onoma2)
% matrix allthenames keeps all the AWFR names (every hour,
%every .xdat file), in integer values
allthenames(filecounter,:)=char(AWFRname)
%and this converts the integer values to a string
AWFRallthenames=char(allthenames)
%Now create the AWFR matrix. NO stimulation intervals included.
AWFR = zeros(nBins, 1);
for n=1:nBins
index_ofeach_bin=find( (Ts>(n-1)*(Fs*60*BinSize)) & (Ts<=n*(Fs*60*BinSize)))
AWFR(n)=length(index_ofeach_bin)
end
%now I pass on the values to the string name I have created before (AWFRname)
%eval([AWFRname,'=AWFR'])
%now I pass on the values of the string name I have created before, and
%rests in a row of the AWFRallthenames matrix
eval([AWFRallthenames(filecounter,:),'=AWFR'])
댓글 수: 3
Geoff Hayes
2014년 5월 8일
Are you getting a particular error, or is the output just not what you expect? Please provide more details or an example of the invalid behaviour and the expected behaviour.
I'm not too clear on the line
eval([AWFRallthenames(filecounter,:),'=AWFR'])
AWFRallthenames is an array/matrix of characters and AWFR is a numeric array. So the code is trying to assign an array of integers to the filecounter row of AWFRallthenames?
dpb
2014년 5월 8일
...for each file I create variable names ... then, I pass on to them the values of a matrix ... using eval()
See
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!