??? Index exceeds matrix dimensions - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

??? Index exceeds matrix dimensions

thisisalexthisisalex Posts: 1Member
I'm deleting a row from a matrix then writing it to a text file and am getting an error
------
??? Index exceeds matrix dimensions.

Error in ==> final_program at 125
fprintf(fid,'%s %s %s %s',guests{i, 1},guests{i, 2},guests{i, 3},guests{i, 4});
------
The matrix is good and I have checked it in MATLAB and it displays exactly how it should. I have this snippet of code working correctly in another switch statement when it needs to replace a cell array and then print to text file but once I try to use it to remove the cell row and print I get this annoying error. Thanks!

Here's the snippet of code in which it occurs.
[code]
% delete row from text file
[guests, lines] = show_guests('hotel.txt');
choices = guests;
choices(:,2:4) = [];
choices = choices';
[reservations, hh] = listdlg('ListString',choices, 'SelectionMode','single');
if hh == 1
% create the new data file
guests(reservations, :) = [];

% write the changes to text file
fid = fopen('hotel.txt', 'w+');
i=1;
for j=i:lines
if i ~= lines
fprintf(fid,'%s %s %s %s
',guests{i, 1},guests{i, 2},guests{i, 3},guests{i, 4});
else
fprintf(fid,'%s %s %s %s',guests{i, 1},guests{i, 2},guests{i, 3},guests{i, 4});
end
i = i+1;
end
fclose(fid);
end
[/code]
Sign In or Register to comment.