<?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 with kWaveDiffusion</title>
		<link>http://www.k-wave.org/forum/topic/error-with-kwavediffusion</link>
		<description>Support for the k-Wave MATLAB toolbox</description>
		<language>en-US</language>
		<pubDate>Wed, 13 May 2026 08:12:04 +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-with-kwavediffusion" rel="self" type="application/rss+xml" />

		<item>
			<title>Bradley Treeby on "error with kWaveDiffusion"</title>
			<link>http://www.k-wave.org/forum/topic/error-with-kwavediffusion#post-6830</link>
			<pubDate>Tue, 09 Apr 2019 09:21:59 +0000</pubDate>
			<dc:creator>Bradley Treeby</dc:creator>
			<guid isPermaLink="false">6830@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;Hi cgenes,&#60;/p&#62;
&#60;p&#62;There seems to be two issues here. The first is a bug in k-Wave for plotting in 3D when the grid size has an odd number of grid points. To fix this, under the &#60;code&#62;plotTemp&#60;/code&#62; method in &#60;code&#62;kWaveDiffusion&#60;/code&#62; for &#60;code&#62;case 3&#60;/code&#62;, replace with the following code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;% plot temperature distribution in x-y plane
subplot(2, 2, 1),
if isnumeric(obj.plot_scale)
    imagesc(obj.y_vec .* obj.plot_axes_scale, obj.x_vec .* obj.plot_axes_scale, squeeze(obj.T(:, :, ceil(obj.Nz/2))), obj.plot_scale);
else
    imagesc(obj.y_vec .* obj.plot_axes_scale, obj.x_vec .* obj.plot_axes_scale, squeeze(obj.T(:, :, ceil(obj.Nz/2))));
end
axis image;

% add plot labels
title(&#38;#39;x-y plane&#38;#39;);

% plot temperature distribution in x-z plane
subplot(2, 2, 2)
if isnumeric(obj.plot_scale)
    imagesc(obj.z_vec .* obj.plot_axes_scale, obj.x_vec .* obj.plot_axes_scale, squeeze(obj.T(:, ceil(obj.Ny/2), :)), obj.plot_scale);
else
    imagesc(obj.z_vec .* obj.plot_axes_scale, obj.x_vec .* obj.plot_axes_scale, squeeze(obj.T(:, ceil(obj.Ny/2), :)));
end
axis image;

% add plot labels
title(&#38;#39;x-z plane&#38;#39;);
xlabel([&#38;#39;(All axes in &#38;#39; obj.plot_axes_prefix &#38;#39;m)&#38;#39;]);

% plot temperature distribution in y-z plane
subplot(2, 2, 3)
if isnumeric(obj.plot_scale)
    imagesc(obj.z_vec .* obj.plot_axes_scale, obj.y_vec .* obj.plot_axes_scale, squeeze(obj.T(ceil(obj.Nx/2), :, :)), obj.plot_scale);
else
    imagesc(obj.z_vec .* obj.plot_axes_scale, obj.y_vec .* obj.plot_axes_scale, squeeze(obj.T(ceil(obj.Nx/2), :, :)));
end
axis image;

% add plot labels
title(&#38;#39;y-z plane&#38;#39;);

% set colormap
colormap(obj.color_map);&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;The second issue is the error you see. I don't know what &#60;code&#62;absorbCube&#60;/code&#62; is (or what it's dimensions are), but if I replace this line with:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;source.Q = 1e7 * makeBall(201, 201, 201, 100, 100, 100, 20);&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;The code seems to run correctly (with the fix above).&#60;/p&#62;
&#60;p&#62;As a final note, it's generally advisable to chose grid sizes with small prime factors - the simulations will run much faster. If you run &#60;code&#62;factor(201)&#60;/code&#62; you can see the largest prime factor is 67. If you run &#60;code&#62;checkFactors(200, 250)&#60;/code&#62;, you can see that 192 or 216 are good numbers to choose.&#60;/p&#62;
&#60;p&#62;Hope that helps,&#60;/p&#62;
&#60;p&#62;Brad.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>cgenes on "error with kWaveDiffusion"</title>
			<link>http://www.k-wave.org/forum/topic/error-with-kwavediffusion#post-6826</link>
			<pubDate>Mon, 08 Apr 2019 14:27:08 +0000</pubDate>
			<dc:creator>cgenes</dc:creator>
			<guid isPermaLink="false">6826@http://www.k-wave.org/forum/</guid>
			<description>&#60;p&#62;HI I'm not quite understudying something basic here as I'm getting this error (see below) I have a 201x201x201 matrix of values in W/m3 which I am trying to get it to calculate on. is I something wrong with my kgrid?&#60;/p&#62;
&#60;p&#62;Running k-Wave thermal simulation...&#60;br /&#62;
  start time: 08-Apr-2019 14:22:38&#60;br /&#62;
  dt: 500ms, t_end: 150s, time steps: 300&#60;br /&#62;
  input grid size: 202 by 202 by 202 grid points (20.2 by 20.2 by 20.2mm)&#60;br /&#62;
Array dimensions must match for binary array op.&#60;/p&#62;
&#60;p&#62;Error in kWaveDiffusion/takeTimeStep (line 689)&#60;br /&#62;
                    q_term = obj.diffusion_p1 .* obj.IT( kappa .* obj.FT( obj.Q ) );&#60;/p&#62;
&#60;p&#62;Error in k_wave (line 61)&#60;br /&#62;
kdiff.takeTimeStep(Nt, dt);&#60;/p&#62;
&#60;p&#62;the code I am running is here:  &#60;/p&#62;
&#60;p&#62;% create the computational grid&#60;br /&#62;
Nx = 201;           % number of grid points in the x (row) direction&#60;br /&#62;
Ny = 201;           % number of grid points in the y (column) direction&#60;br /&#62;
Nz = 201;&#60;br /&#62;
dx = 1e-4;        % grid point spacing in the x direction [m]&#60;br /&#62;
dy = 1e-4;        % grid point spacing in the y direction [m]&#60;br /&#62;
dz =  1e-4;&#60;br /&#62;
kgrid = kWaveGrid(Nx, dx, Ny, dy, Nz, dz);&#60;/p&#62;
&#60;p&#62;% define medium properties&#60;br /&#62;
medium.density              = 1079;     % [kg/m^3]&#60;br /&#62;
medium.thermal_conductivity = 0.52;     % [W/(m.K)]&#60;br /&#62;
medium.specific_heat        = 3540;     % [J/(kg.K)]&#60;/p&#62;
&#60;p&#62;% set Gaussian initial temperature distribution [degC]&#60;br /&#62;
% width = 4 * dx;&#60;br /&#62;
% source.T0 = 37 + 5 .* exp( -(kgrid.x ./ width).^2 - (kgrid.y ./width).^2 );&#60;br /&#62;
T0 = 37 .* ones(201, 201, 201);&#60;br /&#62;
T0(:, 120:201, :) = 20 ;&#60;br /&#62;
source.T0 = T0;&#60;br /&#62;
source.Q = absorbCube;&#60;br /&#62;
% set input args&#60;br /&#62;
input_args = {'PlotScale', [37, 50]};&#60;/p&#62;
&#60;p&#62;% create kWaveDiffusion object&#60;br /&#62;
kdiff = kWaveDiffusion(kgrid, medium, source, [], input_args{:});&#60;/p&#62;
&#60;p&#62;% % take time steps (temperature can be accessed as kdiff.T)&#60;br /&#62;
Nt = 300;&#60;br /&#62;
dt = 0.5;&#60;br /&#62;
kdiff.takeTimeStep(Nt, dt);&#60;br /&#62;
% %&#60;br /&#62;
% % plot the current temperature field&#60;br /&#62;
figure;&#60;br /&#62;
kdiff.plotTemp;
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
