Plotting function, which includes a sum

Hey,
I am trying to plot the structure function of the temperature of measured data. The Data is in a netcdf. file. I am trying to calculate the sum over k and then plot it over x.
This is my code:
startLoc = [497870 536410];
ncread('030608_nc.100Hz_data1','Tt',startLoc);
Temp=ncread('030608_nc.100Hz_data1','Tt');
I
x=[0:10:10000];
k=[497870,536410];
syms k x
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));
plot(x,y);
I then get the following Errors:
>> Sum
Error using internal.matlab.imagesci.nc/read (line 554)
Wrong number of input arguments.
Error in ncread (line 66)
vardata = ncObj.read(varName, varargin{:});
Error in Sum (line 3)
ncread('030608_nc.100Hz_data1','Tt',startLoc);
Thanks for your help :)

1 Commento

I face new errors:
Error using sym/subsindex (line 845)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic
variables, and function body must be sym expression.
Error in Sum (line 12)
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 26 Set 2021
When you provide a start value, you also have to provide a count -- even if you just provide inf as the count.

6 Commenti

thanks, I think I solved this problem. But now I face two new errors:
Error using sym/subsindex (line 845)
Invalid indexing or function definition. Indexing must follow MATLAB indexing. Function arguments must be symbolic
variables, and function body must be sym expression.
Error in Sum (line 12)
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));
Delete the syms k x but keep the assignment to k . Then
f = @(x) reshape(sum((Temp(k(1):k(2)) - Temp((k(1)+k(2)+x(:)))).^2,2), size(x));
y = f(x);
plot(x, y)
first of all. thank you for the effort you make. I changed to code to:
startLoc = [497870];
count = [38540];
ncread('030608_nc.100Hz_data1','Tt',startLoc,count);
Temp=ncread('030608_nc.100Hz_data1','Tt');
x=[0:10:10000];
k=[497870,536410];
f = @(x) reshape(sum((Temp(k(1):k(2)) - Temp((k(1)+k(2)+x(:)))).^2,2), size(x));
y = f(x);
plot(x, y)
then i get this error:
Index exceeds the number of array elements (774818).
Error in Sum>@(x)reshape(sum((Temp(k(1):k(2))-Temp((k(1)+k(2)+x(:)))).^2,2),size(x))
Error in Sum (line 12)
y = f(x);
Remember you ask to start reading at 497870, so that is the location that is going to be at offset 1 in the resulting array.
Use
k=[497870,536410] - startLoc + 1;
thanks, that helped.
Altough I now get a new error:
Matrix dimensions must agree.
Error in Sum>@(x)reshape(sum((Temp(k(1):k(2))-Temp((k(1)+k(2)+x(:)))).^2,2),size(x))
Error in Sum (line 12)
y = f(x);
Your setup is suspect. Suppose you had read in all of the data, then examining your desired
f= matlabfunction(symsum((Temp(k)-Temp(k+x)).^2,k,497870,536410));
with x having a minimum value of 0 maximum value of 10000, then you the indices of the Temp values being subtracted would range from 497870+0 to 536410+10000 which is a span of 48541 items. But your count is count = [38540]; which is 10001 short . Note that 497870:536410 is 38541 items.
What is the index of the first item in Temp(k) that is to appear on the left side of the subtraction? What is the index of the last item in Temp(k) that should appear on the left side of the subtraction? What is the index of the last item in Temp(k+x) that should appear on the right side of the subtraction? Last-on-right - first-on-left + 1 is the count of items that you need to read in (we can worry about fixing up the indexing once the correct number of items is retrieved.)

Accedi per commentare.

Categorie

Scopri di più su Historical Contests in Centro assistenza e File Exchange

Prodotti

Release

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by