이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Dear all,
I have the following command
xlswrite('data_Aus_Di_out'1.xlsx', yy ,'Sheet1', 'A2')
I would like to have something like
k={'data_Aus_Di_out'}
xlswrite('k.xlsx', mdata1 ,'Sheet1', 'A2')
so as to be able to change the name of the excel file OUTSIDE the lxswrite function
thank you
채택된 답변
Image Analyst
2012년 7월 3일
편집: Image Analyst
2012년 7월 3일
Use sprintf() to create whatever base filename you want. Use fullfile() to combine the folder and the base filename into the full path (folder plus base filename). Also, see the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F for examples of how to create a variety of filenames in different ways.
% Make a base file name that has a number embedded in it.
baseFileName = sprintf('dataoutput_Austria_Diapers_output%d.xlsx', k);
% Combine it with the folder to get the full path of the file.
fullFileName = fullfile(folder, baseFileName);
% Now write it out to an Excel workbook.
xlswrite(fullFileName, mdata1 ,'Sheet1', 'A2');
댓글 수: 7
THanks imager. IT works:
myFolder = 'C:\Users\sabbas\Documents\MATLAB\wers';
baseFileName = sprintf('input.xlsx', 1);
fullFileName = fullfile(myFolder, baseFileName);
[num,txt,raw]=xlsread(fullFileName);
[num,txt,raw]=xlsread(fullFileName);
However, the button at the top right of the editor is red. The problem seems to be in
baseFileName = sprintf('input.xlsx', 1);
because when I point the cursor to the this command, I read that
"Format string apparently does not with the argument count"
Why is this the case. can we fix that?
thanks
I noticed that by eliminating the number from baseFileName, that is by having just
baseFileName = sprintf('input.xlsx');
the problem seems to disappear and the code still works. Is my approach risky?
thanks
I don't think you understand sprintf correctly. It will build a string based on a format and a number of arguments that supply data (referenced by the format). In your case, you have not indicated any additional data in the format string.
baseFileName = sprintf('input.xlsx', 1);
That is a roundabout way of doing this:
baseFileName = 'input.xlsx';
Perhaps you meant this (note the '%d' indicates that you have supplied an integer and its value is to be converted to a string and inserted at that location):
baseFileName = sprintf('input%d.xlsx', 1);
I suggest you read the documentation on sprintf:
doc sprintf
Walter Roberson
2012년 7월 4일
If you aren't going to put a number into baseFileName, then don't bother with sprintf().
baseFileName = 'input.xlsx';
Sabbas
2012년 7월 4일
thanks Geoff
I think that the easiest approach is the following
k='output1.xlsx'
xlswrite(k, yy ,'Sheet1', 'A2')
Am I right? In this way I do not need to use "fullfile" etc..
Image Analyst
2012년 7월 4일
Sure, that's easier, but not as robust. If you know for a fact that you always want to put your workbook in the same folder as your m-file, rather than, say the folder where your input data came from or somewhere else, then you can omit the folder and store it in whatever the current directory is. I recommend you read the FAQ: http://matlab.wikia.com/wiki/FAQ#Where_did_my_file_go.3F_The_risks_of_using_the_cd_function. so you don't specify where the workbook should go via the cd function.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
태그
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
