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