Duplicate table variable name: 'VarName2'.
이전 댓글 표시
I have 15 minute interval data of power produced on a daily basis from nine different sources (coal, gas, nuclear etc.) for the month of Jan 2012. I want data in a single column for each source, meaning 9 different columns since I have 9 sources. Currently it is a row wise data for each source for each day of the month. I am using the following code and getting an error (Duplicate table variable name: 'VarName2'.) :
ndata = data;
ndata(:,1)=[];
id = eye(9);
id = repmat(id,31,1); % 31 day
output = [];
for i = 1:9;
one = id(:,i);
one = logical(one);
temp = ndata(one,:);
output = [output temp];
end
Duplicate table variable name: 'VarName2'.
댓글 수: 7
Image Analyst
2021년 5월 9일
I don't see you creating a table in that code. There is no call to the table() function. Nor do I see you calling the "VarName2" field of the table.
Please post the code that threw the error - that means ALL the red text, including the line number, line of code, error message - everything.
Kushal Bhalla
2021년 5월 9일
Scott MacKenzie
2021년 5월 9일
편집: Scott MacKenzie
2021년 5월 9일
I don't see anything wrong in line 10. Of course, the 10th line in the excerpt of code in your question is not the 10th line in the code you are executing. You might consider posting your data (or a subset of the data) and code that can be executed to reproduce the error.
Kushal Bhalla
2021년 5월 9일
Scott MacKenzie
2021년 5월 9일
편집: Scott MacKenzie
2021년 5월 9일
The data portion of the table forms a 279x96 matrix. The columns are 96 measurements on 15-minute intervals. The rows correspond to the 9 sources, repeated 31 times. You are trying to organized the data into 9 columns. Are you looking for 31x96=2976 rows? Please explain.
Kushal Bhalla
2021년 5월 11일
David Ebert
2022년 9월 24일
For the loop, try one easy addition:
Add a ";" in output = [output temp]; so it looks like:
output = [output ; temp];
for i = 1:9;
one = id(:,i);
one = logical(one);
temp = ndata(one,:);
output = [output temp];
end
Cheers,
David
채택된 답변
추가 답변 (1개)
Scott MacKenzie
2021년 5월 9일
편집: Scott MacKenzie
2021년 5월 9일
Here are three solutions. They all give nine columns, one for each source, as per your question. The first table (dataNew1) is a simple reorganization with 31 x 96 = 2976 rows. The second table (dataNew2) aggregates the data by computing the mean value over 31 days in the month. This yields 96 rows, one for each 15-minute interval. The third table (dataNew3) aggregates the data by computing the mean over the 15-minute intervals. This yields 31 rows, one for each day.
data = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/612335/data.csv');
sourceNames = data{1:9,1};
sourceNames = split(sourceNames, '-'); % date + source name
sourceNames = sourceNames(:,2); % just the source name
% reorganize the data (show each step in a separate variable)
d1 = data{:,2:end};
d2 = d1(:);
% organize data into 9 columns and 31x96 = 2976 rows
d3 = reshape(d2,9,[]);
d4 = d3';
dataNew1 = array2table(d4); % 2976x9
dataNew1.Properties.VariableNames = sourceNames;
% organize data into 9 columns and 96 rows
d5 = reshape(d2,9,31,96);
d6 = mean(d5,2); % compute mean over days (31)
d7 = squeeze(d6);
d8 = d7';
dataNew2 = array2table(d8); % 96x9
dataNew2.Properties.VariableNames = sourceNames;
% organize the data into 9 columns and 31 rows
d9 = reshape(d2,9,31,96);
d10 = mean(d9,3); % compute mean over 15-minute intervals (96)
d11 = d10';
dataNew3 = array2table(d11); % 31x9
dataNew3.Properties.VariableNames = sourceNames;
댓글 수: 3
Kushal Bhalla
2021년 5월 11일
Scott MacKenzie
2021년 5월 12일
I believe your original question, as posed, has been answered. If new issues emerge, may I suggest your organize these into a new question. Good luck.
Kushal Bhalla
2021년 5월 16일
카테고리
도움말 센터 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!