MATLAB Answers

Why am I getting the error message "??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts"?

334 ビュー (過去 30 日間)
I do not understand the following error message:
Error Messages: ??? Assignment has more non-singleton rhs dimensions than non-singleton subscripts

採用された回答

MathWorks Support Team
MathWorks Support Team 2017 年 5 月 1 日
This error is a result of incorrect indexing of multidimensional arrays.
For example, you can reproduce the same error message to execute the following command.
>> a = zeros(3,3,3); % difine 3x3x3 size variable 
>> a(3,3,2) = randn(1,2); % assign 1x2 size values
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
To workaround, please check the size of variable you would like to assign.

  3 件のコメント

bh dhouha
bh dhouha 2017 年 10 月 17 日
replace a(3,3,2) by a(3,3,2:3)) for example so that the dimensions agree.

サインインしてコメントする。

その他の回答 (3 件)

Vigneshwar Pesaru
Vigneshwar Pesaru 2017 年 9 月 25 日
I faced the same error its because of following consider x(:,:,1)=[3 1 2;2 1 3;4 5 6]%I am storing this matrix into a variable x,here 1 is my page number to access it in future. x(:,:,2)=[1 2 3 4;2 3 4 5;6 7 8 9]; %this shows you the above error as it is incorrect indexing of multidimensional arrays.%I think both matrices should be of same dimensions

  0 件のコメント

サインインしてコメントする。


chaima kadess
chaima kadess 2018 年 4 月 1 日
編集済み: Walter Roberson 2018 年 4 月 1 日
I faced also the same error with this ligne
seq_images(:,:,p) = dicomread(fullfile(rep,fileNames{p}));

  1 件のコメント

Walter Roberson
Walter Roberson 2018 年 4 月 1 日
You could get that error if dicomread() returned multiple slices, which can happen for some kinds of dicom images. You might possibly be able to use
seq_images(:,:,:,p) = dicomread(fullfile(rep,fileNames{p}));
provided that all of the dicom files have the same number of slices.

サインインしてコメントする。


Daniel Mbadjoun
Daniel Mbadjoun 2019 年 10 月 10 日
Hi all,
I have the same problem. Please help me to fix it.
clear all
clc
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % % %%%read data
% filename = 'D_test2.xlsx';
% sheet = 1;
% xlRange = 'A2:E60';
%
% Mm = xlsread(filename, sheet, xlRange);
% %
% % %Get the data
% % %X=(Mm(:,1:13)); %%% money ens data
% HB=(Mm(:,2)); %%% hauteur brute
% P=(Mm(:,3)); %%% puissance
% QTU=(Mm(:,1));%%débit turbiné
% Rg=(Mm(:,4));
% k=0.00981;
% m=(Mm(:,5));
%
% x1=QTU(:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % %%%read data
% % filename = 'D_final.xlsx';
% % sheet = 1;
% % xlRange = 'A2:AG8761';
% %
% % Mm = xlsread(filename, sheet, xlRange);
% % % pause
% % % Get the data
% % % X=(Mm(:,1:13)); %%% money ens data
% % HB=(Mm(:,17)); %%% hauteur brute
% % P=(Mm(:,1)); %%% puissance
% % QTU=(Mm(:,11));%%débit turbiné
% % % hf=(Mm(:,22));%perte de charge dans la conduite
% % AMONT=(Mm(:,15));%hauteur amont
% % CdF=(Mm(:,16));%hauteur aval
% % % R=(Mm(:,23));%rendement
% % m=(Mm(:,25));%durée
% % % rhf=(Mm(:,26));
% % Rg=(Mm(:,27));
% % k=0.00981;
% % % X=(Mm(:,31));
% % % hmin=36.5;
% % % hmax=41.5;
% % % qmin=130;
% % % qmax=152;
% % x1=QTU(:);
% % hfb=AMONT(:);
% % htr=CdF(:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%P QTU AMONT CdF HB R Rg
GG=[
296 845.7143 528.2500 488 40.2500 0.7475 0.8864
247 705.7143 528.2700 488 40.2700 0.6237 0.8860
246 702.8571 528.2400 488 40.2400 0.6212 0.8866
256 731.4286 528.2000 488 40.2000 0.6465 0.8875
265 757.1429 528.2600 488 40.2600 0.6692 0.8862
286 817.1429 528.2500 488 40.2500 0.7222 0.8864
273 780 528.2300 487.5000 40.7300 0.6894 0.8760
265 757.1429 528.3000 487.5000 40.8000 0.6692 0.8745
351 1.0029e+03 528.1000 487.6000 40.5000 0.8864 0.8809
349 997.1429 528.0600 487.7000 40.3600 0.8813 0.8840
365 1.0429e+03 528 487.7000 40.3000 0.9217 0.8853
359 1.0257e+03 528.1600 487.7000 40.4600 0.9066 0.8818
347 991.4286 528.3000 487.7000 40.6000 0.8763 0.8788
351 1.0029e+03 528.3000 487.7000 40.6000 0.8864 0.8788
368 1.0514e+03 528.2000 487.7000 40.5000 0.9293 0.8809
358 1.0229e+03 528.1400 487.7000 40.4400 0.9040 0.8822
359 1.0257e+03 528.0800 487.7000 40.3800 0.9066 0.8836
346 988.5714 528.1800 487.7000 40.4800 0.8737 0.8814
377 1.0771e+03 528.1500 488 40.1500 0.9520 0.8886
373 1.0657e+03 528.2100 488 40.2100 0.9419 0.8873
376 1.0743e+03 528.2400 488 40.2400 0.9495 0.8866
367 1.0486e+03 528.2000 488 40.2000 0.9268 0.8875
355 1.0143e+03 528.1800 488 40.1800 0.8965 0.8880
309 882.8571 528.2300 488 40.2300 0.7803 0.8868
276 788.5714 528.2500 488 40.2500 0.6970 0.8864
254 725.7143 528.2600 488 40.2600 0.6414 0.8862
253 722.8571 528.2600 488 40.2600 0.6389 0.8862
250 714.2857 528.2700 488 40.2700 0.6313 0.8860
258 737.1429 528.2400 488 40.2400 0.6515 0.8866
292 834.2857 528.1600 488 40.1600 0.7374 0.8884
280 800 528.1600 488.6000 39.5600 0.7071 0.9019
303 865.7143 528.2000 488.6000 39.6000 0.7652 0.9010
312 891.4286 528.1000 488.6000 39.5000 0.7879 0.9032
343 980.0000 528 488.6000 39.4000 0.8662 0.9055
345 985.7143 528.0600 488.6000 39.4600 0.8712 0.9042
333 951.4286 528.1800 488.6000 39.5800 0.8409 0.9014
329 940.0000 528.2400 488.6000 39.6400 0.8308 0.9000
315 900.0000 528.2800 488.6000 39.6800 0.7955 0.8991
338 965.7143 528.2000 488.6000 39.6000 0.8535 0.9010
328 937.1429 528.1000 488.6000 39.5000 0.8283 0.9032
315 900.0000 528.1000 488.6000 39.5000 0.7955 0.9032
317 905.7143 528.1000 488.6000 39.5000 0.8005 0.9032
358 1.0229e+03 528.0400 487.9000 40.1400 0.9040 0.8888
371 1060 528.1200 487.9000 40.2200 0.9369 0.8871
373 1.0657e+03 528.2200 487.9000 40.3200 0.9419 0.8849
364 1040 528.2500 487.9000 40.3500 0.9192 0.8842
348 994.2857 528.2100 487.9000 40.3100 0.8788 0.8851
296 845.7143 528.2400 487.9000 40.3400 0.7475 0.8844
267 762.8571 528.2200 487.9000 40.3200 0.6742 0.8849
242 691.4286 528.2800 487.9000 40.3800 0.6111 0.8836
243 694.2857 528.2800 487.9000 40.3800 0.6136 0.8836
238 680 528.2600 487.9000 40.3600 0.6010 0.8840
242 691.4286 528.2200 487.9000 40.3200 0.6111 0.8849
251 717.1429 528.2000 487.9000 40.3000 0.6338 0.8853
267 762.8571 528.2900 487.3000 40.9900 0.6742 0.8704
222 634.2857 528.1000 487.3000 40.8000 0.5606 0.8745
267 762.8571 527.9000 487.3000 40.6000 0.6742 0.8788
262 748.5714 527.9000 487.3000 40.6000 0.6616 0.8788
270 771.4286 528.1800 487.3000 40.8800 0.6818 0.8727
273 780 528.3000 487.3000 41.0000 0.6894 0.8702];
P=GG(:,1);
QTU=GG(:,2);
hfb=GG(:,3);
htr=GG(:,4);
HB=GG(:,5);
Rg=GG(:,7);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% options = optimset('PlotFcns',@optimplotfval);
%options = optimset('PlotFcns',@optimplotfval);
opts = optimset('fminsearch');
%opts = optimset('fminsearch',@optimplotfval);
opts.Display = 'iter';
opts.TolX = 1.e-12;
%opts.TolFun = 1.e-12;
opts.MaxFunEvals = 100;
sse =@(x)QTU-sum(x(1)+x(2)+x(3)+x(4)+x(5)+x(6)+x(7)+x(8));
x0=[ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1),ones(60,1)];
n=length(x0);
LB=[0*ones(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1) zeros(n,1)];
UB=[152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1) 152*ones(n,1)];
%sse = fminsearch(sse,x0,options)
%xsol = fminsearchbnd(sse,x0,LB,UB,opts)
[xsol,fval,exitflag,output] = fminsearchbnd(sse,x0,LB,UB)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

タグ

タグが未入力です。

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by