generate a random matrix with constraints
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
hello,
I break a question about a problem I have to solve but I do not know if what I want to do is possible. I have a matrix (193.1) I will call A, is a column vector. I want to generate a matrix (193.3) or the sum of line 1 is equal to the value of A (1,1). the values taken by A are between 0.5 and -0.5, it's continues values. My matrix A does not always have the same value or complexity of the problem. If someone has an idea that would help me a lot. Thank you.
採用された回答
Walter Roberson
2014 年 4 月 4 日
12 件のコメント
vachelard
2014 年 4 月 4 日
sory Walter, I just realized that the links led me to a function. I try to run the function but I do not. What should I do to make it work?
Use the download link to download a .zip. Unzip it into a convenient directory (but not under the MATLAB installation directory.) Add the path of the directory that results into the MATLAB path using pathtool. After that in your code,
cols_to_generate = 3;
for K = 1 : length(A)
newA(K,:) = randfixedsum(1, cols_to_generate, A(K), -0.5, 0.5);
end
and then your newA will be 193 x 3 of entries between -0.5 and +0.5, with the sum of the K'th row of newA being A(K)
vachelard
2014 年 4 月 5 日
thank you very much for you help!!
vachelard
2014 年 4 月 5 日
when i use the function i have a message error that says:
"Error in randfixedsum (line 95) x = (b-a)*x(p+repmat([0:n:n*(m-1)],n,1))+a; % Permute & rescale x"
I do not know how to solve the problem
Image Analyst
2014 年 4 月 5 日
Does it give you the error message? Why not tell us? Otherwise, step into the code and at that line, see what the values of all the variables are. So, here is how to solve your problem: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
vachelard
2014 年 4 月 5 日
I'm really sorry I started to make use of matlab and I really difficulties. I do not see how I can change the function i see the line where is my error but i don't know how to solve even with your tuto
Image Analyst
2014 年 4 月 5 日
Hang in there. Don't give up on MATLAB yet. It's not that different than debugging or using any other programming language. You'll learn eventually. Now, did you click in the margin of line 95 to set a breakpoint? A red spot will appear. Run your program and it will stop there with an arrow pointing at that line. Then hover the cursor over the variables in your code editor window, or look in the workspace panel, or type their name into the command window, to see what values they have. What are they?
vachelard
2014 年 4 月 5 日
My error line is as follows:
x = (b-a) * x (p + repmat ([0: n: n * (m-1)] n, 1)) + a; % Switches & rescale x
Where x is [0.5152 0.5152 0.5152]
a = -0.5
b = 0.5
n = 1
m = 3
vachelard
2014 年 4 月 5 日
sory and p=[3 1 2]
vachelard
2014 年 4 月 5 日
Image analyst can i show you something? please
Image Analyst
2014 年 4 月 5 日
You are missing a comma after (m-1)] and before the n. Try it like this:
index = p + repmat ([0: n: n * (m-1)], n, 1)
x = (b-a) * x (index) + a; % Switches & rescale x
Now that will also bomb if index is some fractional number, a negative number, or zero, so be sure you know what indexes you ever might expect to get.
vachelard
2014 年 4 月 5 日
just to be sure I get the correct code. Rhedgefund = Y (:, 1);
cols_to_generate = 3;
for K = 1: length (Y)
Neva (K, :) = randfixedsum (1 cols_to_generate, Y (K), -0.15, 0.15);
end
or Y is my data matrix 193 * 1 which is my target matrix.
その他の回答 (1 件)
vachelard
2014 年 4 月 4 日
Your two answers are good but not exactly give me the desired result. I'll try to explain better.
I expected returns monthly for 15 years. I try to generated a matrix whose sum line by line give me the monthly return of my base matrix. Knowing the values of my matrix generated can be negative. I tried this code but the values are just positive: mat = rand(193, 3); rowsum = sum(mat,2); mat = bsxfun(@rdivide, mat, rowsum);
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
