Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Subscripted assignment dimension mismatch.

Asked by Miguel Valencia

Miguel Valencia (view profile)

on 19 Sep 2013

i have a the following code

clear all
clc
file=input('file name ','s');
fid = fopen(file);
for i = 1:44
    for j = 1:2
        ff(i,j) = fscanf(fid,'%e %e',2);
    end
end
ff

and that results

Subscripted assignment dimension mismatch.

 Error in proyectosuelos (line 12)
        ff(i,j) = fscanf(fid,'%e %e',2);

Tanks

[EDITED, Jan, please format your code properly - Thanks]

0 Comments

Miguel Valencia

Miguel Valencia (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 19 Sep 2013

Maybe you should use cell array ff{i,j} instead of ff(i,j)

0 Comments

Azzi Abdelmalek

Azzi Abdelmalek (view profile)

Answer by Jan Simon

Jan Simon (view profile)

on 19 Sep 2013
ff(i,j) = fscanf(fid,'%e %e',2);

Here "ff(i,j)" is a scalar, while "fscanf(fid,'%e %e',2)" reads two values. For obvious reasons, Matlab cannot store two values inside one element. So perhaps you want:

% clear all    % No, do not clear everything! 
% clc          % Is this useful?!
file = uigetfile('*.*, 'file name ');
fid = fopen(file);
ff = zeros(44, 2, 2);
for i = 1:44
   for j = 1:2
      ff(i,j, :) = fscanf(fid,'%e %e', [1, 2]);
   end
end

0 Comments

Jan Simon

Jan Simon (view profile)

Contact us