Bar function examples do not work

6 ビュー (過去 30 日間)
Matthew
Matthew 2014 年 4 月 4 日
コメント済み: Matthew 2014 年 4 月 4 日
I was having an issue with the bar function, where it would return either the error "Subscript indices must either be real positive integers or logicals" or "Index exceeds matrix dimensions."
To make sure everything was running okay, I copied and pasted one of the examples from "help bar" and entered it:
subplot(3,1,2), bar(0:.25:1,rand(5),1) and I get the following response from MATLAB:
Warning: Integer operands are required for colon operator when
used as index
Subscript indices must either be real positive integers or
logicals.
Now, I'm not really sure where to go from here short of completely reinstalling MATLAB.
Any suggestions? I've already tried restarting MATLAB/rebooting my computer.
Thanks!
EDIT: When I first start MATLAB, the bar function example works correctly. Then, after I import old data, the example bar function no longer works.
Any ideas?

採用された回答

the cyclist
the cyclist 2014 年 4 月 4 日
My guess is that you have a variable named bar in your dataset. Therefore, instead of calling the function bar(), MATLAB is trying to index into a variable named bar.
Avoid naming variables with MATLAB keywords.
  1 件のコメント
Matthew
Matthew 2014 年 4 月 4 日
I feel a little bad for asking this now since it just boiled down to such a simple problem... thanks!

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

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 4 日
Probably you've used bar as a variable. Try this
clear bar
subplot(3,1,2),
bar(0:.25:1,rand(5),1)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by