Save data from a loop with a negative variable

Hey guys :) I have a little question, how can i save data from a loop with a variable evolving between -5 to 5 for example, because when I try to save data by using variable_stored, it says that i have to use positive integer or logical...

1 件のコメント

The Matlab Spot
The Matlab Spot 2013 年 12 月 13 日
Correct me if i am wrong
if a = [-5:1:5];
You are not able to save a in a mat file?

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

回答 (1 件)

Simon
Simon 2013 年 12 月 13 日

0 投票

Hi!
Make a table like
tt = -5:5;
Access your variable with index -3 like
V(tt==-3)
PS: you should not double-post your questions.

3 件のコメント

Patrick Allaglo
Patrick Allaglo 2013 年 12 月 13 日
編集済み: Patrick Allaglo 2013 年 12 月 13 日
Ow Sorry for the double post :( Plz look at my code, i dont know where to put it...
Code :
function f = evalpoly1(p,x,b)
t = length(p);
y = 0;
z = 0;
n = t-1;
e = n:-1:0;
for n = 1:n+1
for C = (x:b);
y = y + p(n) * x^e(n);
z = z + p(n) * b^e(n);
end
end
disp('y = ')
disp(y)
disp('z = ')
disp(z)
end
end
Im trying to save polynomial data with the variable evolving between x and b for example -5 and 5
Simon
Simon 2013 年 12 月 13 日
What are x and b? Are these start and end of interval (-5 and 5)?
t = length(p);
y = 0;
z = 0;
N = t-1;
e = N:-1:0;
tt = x:b;
y = zeros(numel(tt), 1);
for C = (x:b);
for n = 1:N+1
y(tt==C) = y(tt==C) + p(n) * C^e(n);
end
end
Don't mix n (number of coefficients) with n (loop counter)! And see my order of the loops.
Patrick Allaglo
Patrick Allaglo 2013 年 12 月 13 日
Yes x and b are start and end of interval.

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

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2013 年 12 月 13 日

コメント済み:

2013 年 12 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by