Info

This question is closed. Reopen it to edit or answer.

Easy question about loading data

1 view (last 30 days)
Albaihaqi Albaihaqi
Albaihaqi Albaihaqi on 13 May 2011
Closed: MATLAB Answer Bot on 20 Aug 2021
I am not matlab user so I can not do this. I need help.
So I have this syntax:
% testing the gaver-stehfest module
function y=testgstd(L)
% L is the number of coefficients
% (examples: L=8, 10, 12, 14, 16, so on..)
sum=0.0;
L=16;
for l=1:20
t(l)=l * 0.1;
calcv(l)=gavsteh('fun1',t(l),L);
exactv(l)=t(l);
sum=sum+(1- exactv/calcv)^2;
end
result1=[exactv' calcv' calcv'-exactv']
relerr=sqrt(sum)
How do I make the input for calcv is not from t(l)=l*0.1, but from the data I have built, sort of numbers:
1
2
5
10
20
50
100
200
500
...
thank you for your help

Answers (1)

Peter O
Peter O on 13 May 2011
Hi,
If your data is in a vector, you can just pass that data along when you call the testing function:
function
y=testgstd(L,dataVector)
% L is the number of coefficients
% (examples: L=8, 10, 12, 14, 16, so on..)
sum=0.0;
This line here will set L as 16 from hereon, regardless of what %you passed to the function above.
L=16;
I've changed your index variable to i below. It's less likely to be confused with the number '1'. I have also adjusted the for loop to run through the whole data vector.
for i=1:length(dataVector)
t(i)=i * 0.1;
calcv(i)=gavsteh('fun1',dataVector(i),L);
The line below as you wrote it is just going to give you from 0.1 to 10% of the number of elements in dataVector, in 0.1 increments. Is this what you want?
exactv(i)=t(i);
sum=sum+(1- exactv/calcv)^2;
end
result1=[exactv' calcv' calcv'-exactv']
relerr=sqrt(sum)

Community Treasure Hunt

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

Start Hunting!