Info

この質問は閉じられています。 編集または回答するには再度開いてください。

How to optimize this code?Please help me and guide me in this direction.

1 回表示 (過去 30 日間)
Harshitha
Harshitha 2015 年 2 月 20 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
hist11=zeros(256,1); hist12=zeros(256,1); hist13=zeros(256,1); hist21=zeros(256,1); hist22=zeros(256,1); hist23=zeros(256,1); hist31=zeros(256,1); hist32=zeros(256,1); hist33=zeros(256,1); using for loop ?Is there any other approach other than for loop?Please help me and guide me in this direction.
  4 件のコメント
Adam
Adam 2015 年 2 月 20 日
Adding words like "as soon as possible" is more likely to turn people away from answering your question than get people to hurry up!
John D'Errico
John D'Errico 2015 年 2 月 20 日
Yes. The "as soon as possible" addition usually turns me off, as it tends to imply that our time is of less value than the person asking the question.

回答 (3 件)

John D'Errico
John D'Errico 2015 年 2 月 20 日
Or a 3-d array, if your goal is to have them in the same shape as your numbered array names have them?
allHists = zeros(256,3,3);
Now, when you wanted to access hist13, you just use
allHists(:,1,3)
The nice things is all of your arrays are in one place. You can operate on them as an entire array. You can create arrays with many such histograms in them. And you can even access them programmatically, in a loop, for example.

Elias Gule
Elias Gule 2015 年 2 月 20 日
編集済み: Elias Gule 2015 年 2 月 20 日
To store matrices in a matrix you need to use a cell array. A cell array is capable of storing any data type. Hence we are first going to create a 3 x 3 cell array of empty cells; then in each empty cell, we will place a cell array containing a matrix of 256 x 1 zeros; If we tried to put the matrices in a single matrix we would end up with a concatenation of these matrices to a single 768 x 768 matrix.
%% Code begins
hist_ = cell(3,3);
hist_(1:end) = {zeros(256,1)};

Image Analyst
Image Analyst 2015 年 2 月 20 日
Why not use a simple 2d numerical array:
theHists = zeros(256, 9);
  1 件のコメント
Elias Gule
Elias Gule 2015 年 2 月 20 日
編集済み: Elias Gule 2015 年 2 月 20 日
this will only create a matrix of size 256 x 9; if you type hist(1), you get 0 as an answer; which is not what is required. what he/she wanted was a matrix 3 by 3 matrix whose items are each 256 by 1 column vectors.

この質問は閉じられています。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by