Error using zeros, Size inputs must be integers

7 次查看(过去 30 天)
Hi, I have problem with run below code could anyone solve it?
error:
Error using zeros
Size inputs must be integers.
Error in make_image (line 25)
rf_env=abs(hilbert([zeros(tstart*fs-min_sample,1); rf_data]));
code:
f0=3.5e6; % Transducer center frequency [Hz]
fs=100e6; % Sampling frequency [Hz]
c=1540; % Speed of sound [m/s]
no_lines=50; % Number of lines in image
d_x=40/1000/no_lines; % Increment for image
% Read the data and adjust it in time
min_sample=0;
for i=1:no_lines
% Load the result
cmd=['load sim_bmd/rf_ln',num2str(i),'.mat']
eval(cmd)
% Find the envelope
if (tstart>0)
rf_env=abs(hilbert([zeros(tstart*fs-min_sample,1); rf_data]));
else
rf_env=abs(hilbert( rf_data( abs(tstart*fs):max(size(rf_data)) ) ));
end
env(1:max(size(rf_env)),i)=rf_env;
end
% Do logarithmic compression
D=20; % Sampling frequency decimation factor
log_env=env(1:D:max(size(env)),:)/max(max(env));
log_env=log(log_env+0.01);
log_env=log_env-min(min(log_env));
log_env=64*log_env/max(max(log_env));
% Make an interpolated image
ID_bmode=10;
[n,m]=size(log_env)
new_env=zeros(n,m*ID_bmode);
for i=1:n
if(rem(i,100) == 0)
i
end
new_env(i,:)=abs(interp(log_env(i,:),ID_bmode));
end
[n,m]=size(new_env)
fn_bmode=fs/D;
clg
image(((1:(ID_bmode*no_lines-1))*d_x/ID_bmode-no_lines*d_x/2)*1000,((1:n)/fn_bmode+min_sample/fs)*1540/2*1000,new_env)
xlabel('Lateral distance [mm]')
ylabel('Axial distance [mm]')
colormap(gray(64))
%brighten(-0.35)
%axis([-20 20 30 90])
axis('image')
  5 个评论
Adam Danz
Adam Danz 2020-6-20
I'm not going to study this topic for you and try to search through the links on that page to find the releveant section of code that you need to learn. At the very least you could find the exact URL that contains the exact code and find the exact line and then copy that relevant section into a comment so other people don't have to search the internet just to understand what you're asking. You invest hours before we invest minutes.
Steven Lord
Steven Lord 2020-6-20
This section of the code caught my eye as particularly bad.
cmd=['load sim_bmd/rf_ln',num2str(i),'.mat']
eval(cmd)
There is no need to call eval here. [There are limited times when you need to call eval at all.] Use the function form of load. I also recommend calling load with an output argument to read the data from the file into a struct array to avoid potentially overwriting variables that already exist with ones from the MAT-file.
theName = ['sim_bmd/rf_ln' num2str(i) '.mat'];
theData = load(theName)
% to refer to a variable named x from the file (as an example)
theData.x

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by