現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to overwrite labels and data in an excel file?
13 ビュー (過去 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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)