<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>k-Wave User Forum &#187; Topic: Error using expandMatrix when executing kspaceFirstOrder3D function</title>
		<link>http://www.k-wave.org/forum/topic/error-using-expandmatrix-when-executing-kspacefirstorder3d-function</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Thu, 14 May 2026 01:37:51 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.2</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>http://www.k-wave.org/forum/search.php</link>
		</textInput>
		<atom:link href="http://www.k-wave.org/forum/rss/topic/error-using-expandmatrix-when-executing-kspacefirstorder3d-function" rel="self" type="application/rss+xml" />

		<item>
			<title>songhw91 on "Error using expandMatrix when executing kspaceFirstOrder3D function"</title>
			<link>http://www.k-wave.org/forum/topic/error-using-expandmatrix-when-executing-kspacefirstorder3d-function#post-9149</link>
			<pubDate>Sun, 06 Oct 2024 22:40:24 +0000</pubDate>
			<dc:creator>songhw91</dc:creator>
			<guid isPermaLink="false">9149@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi, I've defined a 3d grid and trying to run the kspaceFirstOrder3D function. However, the error message shows &#34;Error using expandMatrix&#60;br /&#62;
exp_coeff must be a 1 or 2 element array.&#60;/p&#62;
&#60;p&#62;Error in kspaceFirstOrder_expandGridMatrices (line 160)&#60;br /&#62;
    source.p0 = expandMatrix(source.p0, expand_size, 0);&#60;/p&#62;
&#60;p&#62;Error in kspaceFirstOrder_inputChecking (line 1558)&#60;br /&#62;
    kspaceFirstOrder_expandGridMatrices;&#60;/p&#62;
&#60;p&#62;Error in kspaceFirstOrder3D (line 574)&#60;br /&#62;
kspaceFirstOrder_inputChecking;&#60;/p&#62;
&#60;p&#62;Error in kWave_PSI_simulation (line 102)&#60;br /&#62;
    sensorDataTmp = kspaceFirstOrder3D(kgrid, medium, source, sensor, input_args{:});&#34;&#60;/p&#62;
&#60;p&#62;I've checked the example script as well, but same issue is happening. It seems that this is something related to built in functions.. I appreciate any solutions. Here is my script for your reference.&#60;/p&#62;
&#60;p&#62;clc; clear; close all;&#60;/p&#62;
&#60;p&#62;%%&#60;br /&#62;
c = 1540;&#60;br /&#62;
fs = 30e6;&#60;br /&#62;
% fc = 2e6;&#60;br /&#62;
% band_width = 50; % percent&#60;br /&#62;
% pass_band = nFc * (1+[-band_width band_width]/100) / nFs * 2;&#60;/p&#62;
&#60;p&#62;bRecord = false;&#60;/p&#62;
&#60;p&#62;% computation settings&#60;br /&#62;
file_name = 'PSI_simulation';&#60;br /&#62;
input_args = {'DataCast', 'single',...&#60;br /&#62;
    'PlotLayout',true,...&#60;br /&#62;
    'PMLInside',false,...&#60;br /&#62;
    'PlotPML',false,...&#60;br /&#62;
    'RecordMovie', bRecord,...&#60;br /&#62;
    'MovieName', file_name,...&#60;br /&#62;
    'MovieProfile', 'MPEG-4'};&#60;/p&#62;
&#60;p&#62;%%&#60;br /&#62;
dir_cur = pwd;&#60;br /&#62;
dirSave = [dir_cur '/../data/Acoustic_simulation/' file_name];&#60;/p&#62;
&#60;p&#62;mkdir(dirSave);&#60;/p&#62;
&#60;p&#62;%% dimension &#38;amp; phantom setup&#60;/p&#62;
&#60;p&#62;% size of the computational grid&#60;br /&#62;
grid_size = 2*[40 40 10]*1e-3; % x, y, z&#60;br /&#62;
grid_interval = [1 1 1]*5e-4;&#60;/p&#62;
&#60;p&#62;Nx = round(grid_size(1)/grid_interval(1));&#60;br /&#62;
Ny = round(grid_size(2)/grid_interval(2));&#60;br /&#62;
Nz = round(grid_size(3)/grid_interval(3));&#60;/p&#62;
&#60;p&#62;kgrid = kWaveGrid(Nx, grid_interval(1), Ny, grid_interval(2), Nz, grid_interval(3));&#60;/p&#62;
&#60;p&#62;axis_x = linspace(-0.5*(Nx-1), 0.5*(Nx-1), Nx)*grid_interval(1);&#60;br /&#62;
axis_y = linspace(-0.5*(Ny-1), 0.5*(Ny-1), Ny)*grid_interval(2);&#60;br /&#62;
axis_z = linspace(0, Nz-1, Nz)*grid_interval(3);&#60;/p&#62;
&#60;p&#62;%% scanning sequence&#60;br /&#62;
scanning_interval = [1 1]*1e-3; % x, y&#60;/p&#62;
&#60;p&#62;scanning_pos_x = -0.5*(grid_size(1)/2):scanning_interval(1):0.5*(grid_size(1)/2);&#60;br /&#62;
scanning_pos_y = -0.5*(grid_size(2)/2):scanning_interval(2):0.5*(grid_size(2)/2);&#60;/p&#62;
&#60;p&#62;[scanning_pos_y, scanning_pos_x] = ndgrid(scanning_pos_x, scanning_pos_y);&#60;/p&#62;
&#60;p&#62;scanning_pos_y_grid = round((scanning_pos_y + grid_size(2)/2)/grid_interval(2))+1;&#60;br /&#62;
scanning_pos_x_grid = round((scanning_pos_x + grid_size(1)/2)/grid_interval(1))+1;&#60;br /&#62;
%% target&#60;br /&#62;
target_pos = [0 0 1; 0 10 1; 10 0 1; 10 10 1; 0 -10 1; -10 0 1; -10 -10 1; -10 10 1; 10 -10 1;&#60;br /&#62;
                % 0 0 2; 0 1 2; 1 0 2; 1 1 2; 0 -1 2; -1 0 2; -1 -1 2; -1 1 2; 1 -1 2;&#60;br /&#62;
                0 0 3; 0 10 3; 10 0 3; 10 10 3; 0 -10 3; -10 0 3; -10 -10 3; -10 10 3; 10 -10 3;&#60;br /&#62;
                % 0 0 4; 0 1 4; 1 0 4; 1 1 4; 0 -1 4; -1 0 4; -1 -1 4; -1 1 4; 1 -1 4;&#60;br /&#62;
                0 0 5; 0 10 5; 10 0 5; 10 10 5; 0 -10 5; -10 0 5; -10 -10 5; -10 10 5; 10 -10 5;&#60;br /&#62;
                % 0 0 6; 0 1 6; 1 0 6; 1 1 6; 0 -1 6; -1 0 6; -1 -1 6; -1 1 6; 1 -1 6;&#60;br /&#62;
                0 0 7; 0 10 7; 10 0 7; 10 10 7; 0 -10 7; -10 0 7; -10 -10 7; -10 10 7; 10 -10 7;&#60;br /&#62;
                % 0 0 8; 0 1 8; 1 0 8; 1 1 8; 0 -1 8; -1 0 8; -1 -1 8; -1 1 8; 1 -1 8;&#60;br /&#62;
                0 0 9; 0 10 9; 10 0 9; 10 10 9; 0 -10 9; -10 0 9; -10 -10 9; -10 10 9; 10 -10 9;]'*1e-3;&#60;/p&#62;
&#60;p&#62;voxel_targets = cart2grid(kgrid, target_pos);&#60;/p&#62;
&#60;p&#62;%% source and sensor&#60;br /&#62;
source_diameter = 1e-3;&#60;br /&#62;
source_mag = 100;&#60;/p&#62;
&#60;p&#62;sensor_diameter = 1e-3;&#60;/p&#62;
&#60;p&#62;sensor_map = zeros(Nx,Ny);&#60;br /&#62;
for k = 1:numel(scanning_pos_x_grid)&#60;br /&#62;
    disc_tmp = makeDisc(Nx, Ny, scanning_pos_x_grid(k), scanning_pos_y_grid(k), round(0.5*sensor_diameter/grid_interval(1)));&#60;br /&#62;
    sensor_map = sensor_map&#124;disc_tmp;&#60;br /&#62;
end&#60;/p&#62;
&#60;p&#62;sensor_mask = zeros(Nx, Ny, Nz);&#60;br /&#62;
sensor_mask(:,:, Nz/2) = sensor_map;&#60;/p&#62;
&#60;p&#62;sensor.mask = sensor_mask;&#60;br /&#62;
%%&#60;br /&#62;
medium.sound_speed = c * ones(Nx, Ny, Nz);                         % [m/s]&#60;br /&#62;
medium.sound_speed(voxel_targets==1) = 1600;          % [m/s]  speed of sound in hard target&#60;br /&#62;
medium.sound_speed(:,:,Nz/2:end) = 340;               % [m/s] speed of sound in air&#60;/p&#62;
&#60;p&#62;medium.density = 1000 * ones(Nx, Nx, Nz);                           % [kg/m^3] Soft tissue density&#60;br /&#62;
medium.density(voxel_targets==1) = 1200;               % [kg/m^3] tissue density of blood&#60;br /&#62;
medium.density(:,:,Nz/2:end) = 1.3;                     % [kg/m^3] density of air&#60;/p&#62;
&#60;p&#62;%%&#60;br /&#62;
% for k = 1:numel(scanning_pos_y)&#60;br /&#62;
for k = 1&#60;br /&#62;
    % make source&#60;br /&#62;
    ball_tmp = makeBall(Nx, Ny, Nz, scanning_pos_x_grid(k), scanning_pos_y_grid(k), Nz/2, round(0.5*source_diameter/grid_interval(1)));&#60;br /&#62;
    ball_tmp(:,:,1:Nz/2-1) = 0;&#60;/p&#62;
&#60;p&#62;    source.p0 = source_mag * ball_tmp;&#60;/p&#62;
&#60;p&#62;    % run the simulation&#60;br /&#62;
    sensorDataTmp = kspaceFirstOrder3D(kgrid, medium, source, sensor, input_args{:});&#60;br /&#62;
end
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
