フィルターのクリア

error undefined variable 'A' or class 'A'

2 ビュー (過去 30 日間)
Bhargavkrishna Kondreddy
Bhargavkrishna Kondreddy 2017 年 3 月 6 日
コメント済み: Walter Roberson 2017 年 3 月 6 日
for k = 1:299
Xsum = A{k}{:,3};
Xsum(isnan(Xsum)) = 0;
Xsum=Xsum+A{k}(:,3);
end
after excuting getting an error as undefined variable or class

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 3 月 6 日
You have not assigned anything to A before you executed this.
  2 件のコメント
Bhargavkrishna Kondreddy
Bhargavkrishna Kondreddy 2017 年 3 月 6 日
How to assign the values as the 'A' is a matrix like variable. can you please help in solving this?
Walter Roberson
Walter Roberson 2017 年 3 月 6 日
For example,
A = arrayfun(@(IDX) {IDX+[1 1.1 1.2], IDX+[2 2.1 2.2 2.3], randi(IDX, 5, 7), IDX+[4 4.1 4.2 4.3 4.4 4.5].'}, 1:299, 'Uniform', 0);
This will get you through the
Xsum = A{k}{:,3};
Xsum(isnan(Xsum)) = 0;
lines. It will, however, fail on your
Xsum=Xsum+A{k}(:,3);
line.
Look more carefully at how you are using A. In the line
Xsum = A{k}{:,3};
you are declaring that A{k} is a cell array that contains cell arrays. But in
Xsum=Xsum+A{k}(:,3);
you are declaring that A{k}(:,3) is something that can be added, which implies that A{k}(:,3) is numeric, which would require A{k} to contain a numeric array rather than a cell array.
Note: if your intention is to create a running total of all of the entries, then you need to be using the structure
total = 0;
for ....
new_value = ...
total = total + new_value;
end

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by