definision of string variables's dimension

4 次查看(过去 30 天)
Dear.Roberson
Thanks for your tips on decreasing of the program runtime through the definition of variable's dimensions.
I revised my program by making variable's dimensions, but the runtime didn't change.
Can you tell me what the problem is?
I also have another question:
How can I define the dimension of string variables at the begining of the program.
for example: in the program below "normality(j)" is a string variable and I want to define the dimension of this variables at the begining of the program. How can I do it?
for j=1:num_col test_normal(j)=lillietest(q(:,j));
if test_normal(j)==0
normality(j)={'OK'};
else
normality(j)={'___'};
q(:,j)= log10(q(:,j));
normality_log(j)=lillietest(q(:,j));
if test_normal(j)==1 && normality_log(j) ==1; num_non_normal=num_non_normal+1; non_normal_ETO=j; end end end
thanks alot,

采纳的回答

Walter Roberson
Walter Roberson 2012-1-20
Your normality array is an example of a cell array. You can initialize it as
normality_array = cell(num_col,1);
With regards to runtime, if you are referring to this question, I said that "part of the reason" for slowness was preallocation. Depending on your variable sizes, the cost of memory allocation might not be much compared to other factors.
There may be other improvements that can be made, but that's a topic for the other question.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by