フィルターのクリア

Matlab error: ??? The left hand side is initialized and has an empty range of indices.

1 回表示 (過去 30 日間)
Christopher Drew
Christopher Drew 2013 年 6 月 13 日
I'm trying to run the following code and get the error in the subject line above. It only occurs when I load the [] into handles.Filelist. Why does it show this error?
initial conditions are:
handles.Numfiles=1;
handles.Filelist=[];
FileName='Test1.mat';
[FileName, PathName]=uigetfile;
handles.Numfiles=handles.Numfiles+1;
%enter new entry into file list
handles.Filelist{handles.Numfiles,:}=[FileName]; %The error occurs here

回答 (2 件)

Walter Roberson
Walter Roberson 2013 年 6 月 13 日
編集済み: Walter Roberson 2013 年 6 月 13 日
You start with an empty array, 0 x 0. You index that array at with an integer as the first index, and ":" as the second index. As the array is currently 0 x 0, the ":" referring to "all defined array indices" in the second dimension is going to take on the size of the current second dimension and so is going to take on size 0. So you are trying to initialize a 1 x 0 cell array with something that is not empty.
The meaning of A{B,:} is different when A is defined than when A is undefined. When A is undefined, A{B,:} would mean to initialize A with as many second dimension values as needed, but when A is defined then A{B,:} has to match the existing number of dimensions.
Interestingly, I found an inconsistency:
clear h
h{3,:} = 'hello'
h will then become a 1 x 1 cell containing 'hello'. Furthermore,
clear h
h{-5,:} = 'hello'
will be allowed !! with h becoming the same 1 x 1 cell.
But
clear h
h(3,:) = {'hello'}
will create a 3 x 1 cell with the first two empty and the third 'hello'
Meanwhile,
clear h
[h{3,:}] = 'hello'
The left hand side has h{:} inside brackets, which requires that h be defined, so that the number of expected results can be computed.
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 6 月 13 日
Anyhow what you probably want is
handles.Filelist{handles.Numfiles} = FileName;

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


Kwen
Kwen 2013 年 6 月 13 日
It looks like you should use a while loop instead of trying to implement this manually.
  1 件のコメント
Walter Roberson
Walter Roberson 2013 年 6 月 13 日
A while loop around the assignment would not solve the problem.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by