error using zeros,integers problem

2 ビュー (過去 30 日間)
kostas zervos
kostas zervos 2016 年 9 月 9 日
コメント済み: kostas zervos 2016 年 9 月 9 日
i have this code
x = 1 +((riskf_end - riskf_start)/riskf_step);
y = 1 +((volatility_end - volatility_start)/volatility_step);
A = zeros(1 + x, 1 + y);
x and y are integers but the output of y is in exp notation and the 'zeros' command takes y as non integer. i can't figure this out.I tried 'format long g' but again the matrix does not recognize y as an integer.
riskf_end = 0.04
riskf_start = 0
riskf_step = 0.001
volatility_start = 0.13
volatility_step = 0.0001
volatility_end = 0.25
when putting volatility_step = 0.001 the problem disappears, but for smaller steps it apears again.x and y are always integers as the step will always be smaller than the boundaries. I would appriciate any help.Thanks in advance.


Mischa Kim
Mischa Kim 2016 年 9 月 9 日
Why not simply round the numbers, e.g.
A = zeros(1 + round(x), 1 + round(y));
  4 件のコメント
kostas zervos
kostas zervos 2016 年 9 月 9 日
I think i found a solution.Instead of dividing end-start with step,i do it seperately, end/step - start/step.The problem disappeared and the outputs are presented as integers.Thanks for the answers guys,i appriciate it.If the problem reappears i will try rounding the numbers.


その他の回答 (0 件)


Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by