Attempted to access x_set(:,100); index out of bounds because size(x_set)=[7600,1] help

1 回表示 (過去 30 日間)
ajk1
ajk1 2015 年 4 月 16 日
編集済み: ajk1 2015 年 4 月 16 日
Hi, I get an error message after trying to remove values in x_table less than 0. x_table is a 100x100 array and after I apply this condition it changes to a 7660x1 array, resulting in an error when I try to access specific elements in y. How can I correctly remove the elements less than 0? Also it_5 = 1:100 earlier in the code.
x_target = 1:round(max(max(x_table)));
x_target_low = x_target-0.5;
x_target_up = x_target+0.5;
x_set=x_table(x_table>0); %worked before adding (x_table>0)
for it_6 = round(min(min(x_set))):round(max(max(x_set)))
y = find(((x_set(:,it_5)>x_target_low(it_6)).*(x_set(:,it_5)<x_target_up(it_6)))>0);
end

採用された回答

Thorsten
Thorsten 2015 年 4 月 16 日
Rather than removing, set them to NaN. Otherwise you cannot preserve the 100x100 configuration:
x(x<0) = NaN;

その他の回答 (1 件)

James Tursa
James Tursa 2015 年 4 月 16 日
編集済み: James Tursa 2015 年 4 月 16 日
Typically one would remove entire rows or entire columns if you want to preserve the 2D matrix. By removing individual elements that could be scattered throughout the matrix you force the result into 1D. E.g., this condition
x_table>0
Can you elaborate on what exactly you want removed from the 2D matrix based on this condition, and why you think the result should still be 2D?
  2 件のコメント
ajk1
ajk1 2015 年 4 月 16 日
Hi James, I have tried using the 1D result but get errors doing so because it doesn't work with earlier parts of the code that need the result to be in 2D. Optimally I would like help with removing elements that are less than 0. I can try remvoing rows with this condition but don't know how to implement this.
ajk1
ajk1 2015 年 4 月 16 日
編集済み: ajk1 2015 年 4 月 16 日
Thanks for your comment, that as well as Thorstens response both helped, everything seems to be working.

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

カテゴリ

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