Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

1 次查看(过去 30 天)
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