Subscription assignment dimension mismatch error?

1 view (last 30 days)
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

Answers (1)

Mischa Kim
Mischa Kim on 4 Feb 2014
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.

Tags

Community Treasure Hunt

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

Start Hunting!