필터 지우기
필터 지우기

Subscription assignment dimension mismatch error?

조회 수: 1 (최근 30일)
A
A 2014년 2월 4일
답변: Mischa Kim 2014년 2월 4일
I'm trying to take a user input and put it into a matrix. I've set up a dialog box into which the user inputs four values. Each of these values should then be put into a seperate cell in a matrix. However, there seems to be an issue with with user input, no matter how I enter the test cases, it returns a 'Subscription assignment dimension mismatch' error
Here is the code I'm using;
A=zeros(detector_no,4); for j=1:detector_no
prompt={'What is the Postition of the Detector and Compton Angle? x_0, y_0,z_0 theta'};
title='Detector ''X,Y,Z'' Position and Compton Angle, θ';
lines=1;
def={'0','0','0','0'};
answer=inputdlg(prompt,title,lines,def);
A(j,1)=str2num(cell2mat(answer(1)));
A(j,2)=str2num(cell2mat(answer(2)));
A(j,3)=str2num(cell2mat(answer(3)));
A(j,4)=str2num(cell2mat(answer(4)));
end

답변 (1개)

Mischa Kim
Mischa Kim 2014년 2월 4일
How about:
...
lines = 4;
answer = inputdlg(prompt,title,lines,def);
A(1,:) = str2num(answer{1}(1,:));
A(2,:) = str2num(answer{1}(2,:));
A(3,:) = str2num(answer{1}(3,:));
A(4,:) = str2num(answer{1}(4,:));
...
which works for one detector. For j detectors, you could simply add another dimension to A.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by