contour plot issue

8 ビュー (過去 30 日間)
Dominic Lawson
Dominic Lawson 2011 年 3 月 30 日
Hello,
I am sorry to pester you all again but I can't get my code to work. Here is what I have so far:-
clear all % clears all previous data
s = load('domain\data.txt');
% loads in data file
% s(:,1) data number
% s(:,2) x variables
% s(:,3) y variables
x = s(:,2);
y = s(:,3);
a = 9.5:1/100:10.49;
b = 4.5:1/100:5.49;
chi2 = [ ];
c = 0;
for n = 1:100;
for m = 1:100;
a_pred = a(:,n);
b_pred = b(:,m);
c = c+1;
y_pred = a_pred + b_pred.* x;
chi2(c,:) = sum((y-y_pred).^2);
end
end
deltachi = chi2 - min(chi2);
contour(a,b,deltachi);
about the data of s
size(x)
ans =
1000 1
and
size(y)
ans =
1000 1
At the moment I cannot complete a successful contour plot as both chi2 and deltachi are just strings and not arrays. Can anyone see where I am going wrong please?

採用された回答

Walter Roberson
Walter Roberson 2011 年 3 月 30 日
Since y and y_pred are vectors, sum((y-y_pred).^2) is going to be a scalar, so chi2(c,:) is going to be storing a single value. Your chi2 array is going to be a vector of length max n times max m, 100 times 100. Perhaps you want to reshape it to max m by max n using reshape() and then contour that? Or easier yet, just assign to chi2(m,n) and skip using c.
  1 件のコメント
Dominic Lawson
Dominic Lawson 2011 年 3 月 30 日
Thanks very much for the help. It is much appreciated.

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by