Unable to perform assignment

5 views (last 30 days)
Mehmet Sahiner
Mehmet Sahiner on 19 Oct 2020
Commented: drummer on 20 Oct 2020
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 Comments
Image Analyst
Image Analyst on 19 Oct 2020
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).
Mehmet Sahiner
Mehmet Sahiner on 19 Oct 2020
Sorry I forgot to attach it at first but you can chek the data from here.

Sign in to comment.

Answers (1)

drummer
drummer on 19 Oct 2020
Is num two column variable?
I wonder you should choose num(:, 1) or num(:, 2) to assign mgdata(:, 2).
  2 Comments
Mehmet Sahiner
Mehmet Sahiner on 19 Oct 2020
Yes it's a column variable.
I have attached the data for your review. I still couldn't get it in which part I am doing a mistake.
drummer
drummer on 20 Oct 2020
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.

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!