a couple of question
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi all, I have a couple of question. I would appreciate if somebody replies me. The mentioned questions are as below:
1: I want to define all variables of my program as 'Integer ' ones in the way they occupy minimal memory. I used the 'unit8' or 'int8' commands but they don't work properly and I encountered some errors. How can I define for example variable's' as the integer one in the following program?
clear; clc; tic;
ns=10;
s_min= 200;
s_max= 1450;
s=floor ([s_min:(s_max-s_min)/(ns-1):s_max]);
toc
2:I have some varias e.g. "s2, tsd, etc' . I want to preallocate them befor using in the main program like below.
clc; clear; tic;
T=12; ns=10; big_num=10000; nq=23; nr=20;
s2=cell(T,ns);
tsd=cell(T,ns);
r_opt=cell(big_num,ns);
tsd_total=r_opt;
fmin_init=cell(big_num,1);
tsd_intrpln=cell(big_num,nq);
for n=1:big_num
for ss=1:ns
if n<=T; t=n; s2{t,ss}=ones(nq,nr)*8888; sd{t,ss}=ones(nq,nr)*88888; end
r_opt{n,ss}=repmat(88888888,nq,nr);
tsd_total{n,ss}= r_opt{n,ss};
end
fmin_init{n,1}= repmat(88888888,ns,nq);
for qq=1:nq
tsd_intrpln{n,qq}=repmat(88888888,nq,nr);
end
end
toc
In your idea how can I do it using minimum or without any for loops?
3: I have a very time-consuming program. I want to alarm me whenever the running has been finished. I used "beep on" command and turned on the speaker, but it doesn't work. Can you help me?
0 commentaires
Réponses (1)
Image Analyst
le 5 Mai 2012
For question 1, to create an array of all ones:
s=ones(1, ns, 'uint8')
I'm not sure what your s is doing - it's creating a ramp, which is not creating an array of all integer 1's like you want. Creating a ramp is better done by linspace(). Maybe you want to threshold, something like
s = linspace(s_min, s_max, 9) % Easier way than how you made s.
sOnes = uint8(s > 800) % Threshold and cast to uint8
0 commentaires
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!