seeking help with xlswrite function

조회 수: 1 (최근 30일)
John
John 2013년 1월 6일
Hi,
I'm trying to loop through this code 3 times and save the variable states to the excel file. I want to name the excel files 1.xls, 2.xls and 3.xls.
Could anybody tell me what I am doing wrong with the xlswrite as it is not working. Thank you.
for j=1:3
transC = [zeros(size(T,1),1), cumsum(T,2)]; %cumulative sum of rows, we will use this to decide on the next step.
n = 10000;
states = zeros(1,n); %storage of states
states(1) = 32; %start at state 1 (or whatever)
for ii = 2:n
%Generate a random number and figure out where it falls in the cumulative sum of that state's trasition matrix row
[~,states(ii)] = histc(rand,transC(states(ii-1),:));
end
xlswrite('C:\j.xls',[states],'Sheet1', 'A2');
end
  댓글 수: 1
Matt J
Matt J 2013년 1월 6일
We're waiting for you to tell us what the outcome of the code is.

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

채택된 답변

Image Analyst
Image Analyst 2013년 1월 6일
You need to construct the filename properly. Replace this:
xlswrite('C:\j.xls',[states],'Sheet1', 'A2');
with this:
baseFileName = sprintf('%d.xls', j);
fullExcelFileName = fullfile(yourFolder, baseFileName); % yourFolder can be pwd if you want.
xlswrite(fullExcelFileName ,[states],'Sheet1', 'A2');
  댓글 수: 1
John
John 2013년 1월 6일
Thank you for your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by