Unable to perform assignment
1 回表示 (過去 30 日間)
古いコメントを表示
From my attached code and get the following error:
"Unable to perform assignment because the size of the left side is 5689-by-1 and
the size of the right side is 5689-by-2."
clear
clc
close all
%% Time Series Data
filename = 'JCl_Daily.xlsx';
% read the data set
[ num, txt, raw ] = xlsread(filename);
txt = txt(3:end, :);
raw = raw(3:end, :);
mgdata = zeros(length(num),2);
mgdata(:,1) = 1:length(num) ;
mgdata(:,2) = num ;
% load mgdata.dat
%learning data construction
time = mgdata(:, 1) ;
x = mgdata(:, 2);
plot(time,x,'-r')
title('Mackey-Glass Chaotic Time Series')
xlabel('Time (sec)')
ylabel('x(t)')
%% Preprocess Data
for t = 19:length(num)-6
Data(t-17,:) = [x(t-18) x(t-12) x(t-6) x(t) x(t+6)];
end
trnData = Data(1:900,:);
chkData = Data(901:end,:);
%% Build Initial Fuzzy System
fis = genfis(trnData(:,1:end-1),trnData(:,end),...
genfisOptions('GridPartition'));
figure
subplot(2,2,1)
plotmf(fis,'input',1)
subplot(2,2,2)
plotmf(fis,'input',2)
subplot(2,2,3)
plotmf(fis,'input',3)
subplot(2,2,4)
plotmf(fis,'input',4)
%% Train ANFIS Model
options = anfisOptions('InitialFIS',fis,'ValidationData',chkData);
[fis1,error1,ss,fis2,error2] = anfis(trnData,options);
figure
subplot(2,2,1)
plotmf(fis2,'input',1)
subplot(2,2,2)
plotmf(fis2,'input',2)
subplot(2,2,3)
plotmf(fis2,'input',3)
subplot(2,2,4)
plotmf(fis2,'input',4)
%% Plot Errors Curves
figure
plot([error1 error2])
hold on
plot([error1 error2],'o')
legend('Training error','Checking error')
xlabel('Epochs')
ylabel('Root Mean Squared Error')
title('Error Curves')
%% Compare Original and Predicted Series
anfis_output = evalfis(fis2,[trnData(:,1:4); chkData(:,1:4)]);
figure
index = 24:length(num);
plot(time(index),anfis_output,'-b')
hold on
plot(time,x,'-r')
xlabel('Time (sec)')
legend('ANFIS Prediction','Initial Time Series' )
%% error evaluation
figure
diff = x(index) - anfis_output;
plot(time(index),diff)
xlabel('Time (sec)')
title('Prediction Errors')
5 件のコメント
Image Analyst
2020 年 10 月 19 日
You forgot to attach 'JCl_Daily.xlsx' for some reason (like you didn't read the posting guidelines).
Evidently mgdata does not have two columns (yet).
回答 (1 件)
drummer
2020 年 10 月 19 日
Is num two column variable?
I wonder you should choose num(:, 1) or num(:, 2) to assign mgdata(:, 2).
2 件のコメント
drummer
2020 年 10 月 20 日
The documentation says xlsread is not recommended anymore.
You'd rather try using readtable.
It's a suggestion. Let us know if it works:
T = readtable('JCl_Daily.xlsx', 'PreserveVariableNames', true);
T(1:5, :) % checking the first five pair date - number elements
columnArray = T(:, 2); % table type of the second column variable. Just checking. Not really necessary.
num = table2array(T(:, 2)); % converting table to column-array.
% Then
mgdata(:, 1) = size(num);
mgdata(:, 2) = num;
One thing to notice in your file:
The size is [5689 , 1] taking into account the header name. Data itself is [5688, 1].
If that works, please accept the answer.
Cheers.
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!