이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
How to overwrite labels and data in an excel file?
조회 수: 17 (최근 30일)
이전 댓글 표시
If I have an Excel file having labels in columns A1,B1,C1,D1,E1,F1,G1,H1,I1 and J1. Below the labels are numeric data. Now if I want to overwrite the labels in B1,E1,G1. Also if I want to overwrite the numeric data below E1 and G1, how will I do that?
답변 (1개)
Ameer Hamza
2020년 10월 16일
편집: Ameer Hamza
2020년 10월 16일
All of the following functions for writing to excel sheet support 'range' option for writing to excel file
You can specify the range like B1:B100 to replace the first 100 cells of column B in the excel sheet.
댓글 수: 14
Sadiq Akbar
2020년 10월 16일
Thank you very much Ameer Hamza for your consistant help. I visited the site but again it seems too technical for me. I am attaching an excel file.
Suppose I want to overwrite the label fmin in column C with functionminumum. Likewise I want to overwrite Error in Amplitude1 with EA1, Amplitudes MSE with MSE of Amplitudes.
Further, I want to overwrite data in Column C, F,M with any random data.So how will I do that via Matlab code?
Ameer Hamza
2020년 10월 16일
Here is an easy method for your excel file
data = readtable('myfile2sn01.xlsx', 'PreserveVariableName', true);
data.Properties.VariableNames{3} = 'functionminumum';
data.Properties.VariableNames{6} = 'EA1';
data.Properties.VariableNames{13} = 'MSE of Amplitudes';
data{:, 3} = rand(size(data,1), 1);
data{:, 6} = rand(size(data,1), 1);
data{:, 13} = rand(size(data,1), 1);
Sadiq Akbar
2020년 10월 17일
Thank you very much Ameer Hamza for your devoted support and help. I ran the above program, but it gives me the following Error:
>> Excel_Overwrite
Error using readtable (line 197)
Invalid parameter name: PreserveVariableName.
Error in Excel_Overwrite (line 1)
data = readtable('myfile2sn01.xlsx', 'PreserveVariableName', true);
>>
Walter Roberson
2020년 10월 17일
Leave out 'PreserveVariableName', true in your release.
Also the line
data.Properties.VariableNames{13} = 'MSE of Amplitudes';
will have to be changed to assign something that is a valid MATLAB variable name.
If you need 'MSE of Amplitudes' complete with space to be written into the file then we will need to take a bit different approach.
Sadiq Akbar
2020년 10월 17일
편집: Walter Roberson
2020년 10월 17일
Thank you very much Walter Roberson for your tip. I changed the above program. This time it ran but the desired labels and data were not overwritten. Further Matlab gave me a warning message as:
>> Excel_Overwrite
Warning: Variable names were modified to make them valid MATLAB identifiers. The original
names are saved in the VariableDescriptions property.
>>
The chnaged program is as below:
data = readtable('myfile2sn01.xlsx');
data.Properties.VariableNames{3} = 'functionminumum';
data.Properties.VariableNames{6} = 'EA1';
data.Properties.VariableNames{13} = 'MSE_of_Amplitudes';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Overwrite Data in Columns 3,6 and 13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data{:, 3} = rand(size(data,1), 1);
data{:, 6} = rand(size(data,1), 1);
data{:, 13} = rand(size(data,1), 1);
Walter Roberson
2020년 10월 17일
Modified variable name warning is just a warning.
You are not writing the data variable to a file.
Sadiq Akbar
2020년 10월 17일
Thank you very much Walter Roberson. I am not too much technical. How will we write it to the file, "myfile2sn01.xlsx" , I have given in the attachment? Can you guide me further?
Ameer Hamza
2020년 10월 17일
편집: Ameer Hamza
2020년 10월 17일
@Sadiq, you can use writetable()
writetable(data, 'filename.xlsx')
Sadiq Akbar
2020년 10월 17일
Thank you very much dear Ameer Hamza for your consistant help. Yes, it worked for the labels. But it didn't work for the numerical data. Further, it filled column "K" data from row33 till end with hashes i.e. ####.
I am attaching the file for your observation.
Ameer Hamza
2020년 10월 17일
I am not sure about the issues. These commands work fine in R2020b. The output file I get is attached.
Sadiq Akbar
2020년 10월 17일
Thank you very much dear Ameer Hamza. Indeed you are a true helper. I am very happy from you. Ok I will try to arrange Matlab 2020b if I could. But currently I am not having it. Its expensive too. Thank you very much once again. May you live long to keep helping the needy like me.
Sadiq Akbar
2020년 10월 18일
https://www.mathworks.com/matlabcentral/answers/617363-how-to-get-a-cdf-plot-of-my-data
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)