Tag Archives: matlab
Without entering incident angle signal collection by phased.collector
Hey,
I want to send signal from source then will i be able to collect from antennas that are ula, without entering incident angle into collector function.
ex.
rxsig = collector(signal, inc_angle);
Collect all signals and finding angle using phase difference between linear antennasHey,
I want to send signal from source then will i be able to collect from antennas that are ula, without entering incident angle into collector function.
ex.
rxsig = collector(signal, inc_angle);
Collect all signals and finding angle using phase difference between linear antennas Hey,
I want to send signal from source then will i be able to collect from antennas that are ula, without entering incident angle into collector function.
ex.
rxsig = collector(signal, inc_angle);
Collect all signals and finding angle using phase difference between linear antennas phased array, collector MATLAB Answers — New Questions
Unable to assign Input Data in the Parameter Estimation tool
Hello everyone. I am trying to learn the parameter estimation tool in Simulink. However, I cannot figure out how to import the Input data. Output data is the only section that appears on screen. Every tutorial I encountered, like here: Estimate Parameters from Measured Data – MATLAB & Simulink – MathWorks Benelux , there is a distinct Input tab. Am I doing something wrong? I cannot find anyone else who had the same issue. Thx!Hello everyone. I am trying to learn the parameter estimation tool in Simulink. However, I cannot figure out how to import the Input data. Output data is the only section that appears on screen. Every tutorial I encountered, like here: Estimate Parameters from Measured Data – MATLAB & Simulink – MathWorks Benelux , there is a distinct Input tab. Am I doing something wrong? I cannot find anyone else who had the same issue. Thx! Hello everyone. I am trying to learn the parameter estimation tool in Simulink. However, I cannot figure out how to import the Input data. Output data is the only section that appears on screen. Every tutorial I encountered, like here: Estimate Parameters from Measured Data – MATLAB & Simulink – MathWorks Benelux , there is a distinct Input tab. Am I doing something wrong? I cannot find anyone else who had the same issue. Thx! simulink, parameter estimation MATLAB Answers — New Questions
Matalb 2021a uses 100% CPU and is running very slowly
Hello,
I haven’t used Matlab in the few months on my Mac OS ver 10.14.6, and not sure what happened but Matlab R2021a runs very slowly and uses 100% CPU. I’ve already updated R2021a with the update patch. Made sure Editor doesn’t start with the start of MATLAB. There are no viruses, as far as I know. Starting it up using Terminal does not solve the problem.Hello,
I haven’t used Matlab in the few months on my Mac OS ver 10.14.6, and not sure what happened but Matlab R2021a runs very slowly and uses 100% CPU. I’ve already updated R2021a with the update patch. Made sure Editor doesn’t start with the start of MATLAB. There are no viruses, as far as I know. Starting it up using Terminal does not solve the problem. Hello,
I haven’t used Matlab in the few months on my Mac OS ver 10.14.6, and not sure what happened but Matlab R2021a runs very slowly and uses 100% CPU. I’ve already updated R2021a with the update patch. Made sure Editor doesn’t start with the start of MATLAB. There are no viruses, as far as I know. Starting it up using Terminal does not solve the problem. r2021a slow, 100% cpu, crashes MATLAB Answers — New Questions
How to call the embedded code using user defined function blocks in matlab
I have some stm32 codes and i need to integrate that in matlab environment using s function/ c function / c caller blocks. And that particular code have one main header and source and also other librray files that is associated with the stm board. Can someone help me with intergrating that particular code with simulink environment and test that functions.
And if I have to use s function block for above problem how to do that?I have some stm32 codes and i need to integrate that in matlab environment using s function/ c function / c caller blocks. And that particular code have one main header and source and also other librray files that is associated with the stm board. Can someone help me with intergrating that particular code with simulink environment and test that functions.
And if I have to use s function block for above problem how to do that? I have some stm32 codes and i need to integrate that in matlab environment using s function/ c function / c caller blocks. And that particular code have one main header and source and also other librray files that is associated with the stm board. Can someone help me with intergrating that particular code with simulink environment and test that functions.
And if I have to use s function block for above problem how to do that? c caller, s-function, c function, embedded MATLAB Answers — New Questions
Real-Time DAC with DSP tool box
I am having trouble implementing a real time DAC in my code. I am working with an NI USB-6356 and I have succesfully implemented in my Matlab Code an ADC than reads the real time signal and process it. I am trying to implement a DAC with the DSP tool box (as I did with the ADC) but for some reason it doesn’t work. There aren’t any apparent errors so it is being difficult to solve the problem. Can someone tell me what’s happening?
dev = ‘Dev1’;
channels = {‘ai0’, ‘ai1’};
ao = ‘ao0’; % DAC output channel
fs = 1000; % Sampling Frequency
fc = 10; % Carrier Frequency
fsub = 10; % Subcarrier Frequency
D = 1; % Decimation factor
bits = 16; % DAC Resolution
Kc = 0.01; % Proportional control gain
% Create TimeScope for visualization
scope = timescope(‘NumInputPorts’, 3, ‘TimeSpan’, 2, ‘SampleRate’, fs, …
‘ShowLegend’, true, ‘YLimits’, [-5 5], …
‘Title’, ‘Real-time Signal and Processed Signal’, …
‘ChannelNames’, {‘DAC Output’, ‘Input Signal’, ‘Modulated Signal’});
%% Data Acquisition Setup
daqSession = daq.createSession(‘ni’);
for i = 1:length(channels)
addAnalogInputChannel(daqSession, dev, channels{i}, ‘Voltage’);
end
daqSession.Rate = fs;
daqSession.IsContinuous = true;
addAnalogOutputChannel(daqSession, dev, ao, ‘Voltage’);
% Initialize NCO phase accumulator
nco_phase = 0;
lh = addlistener(daqSession, ‘DataAvailable’, …
@(src, event) processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D));
% Create an initial buffer to queue for DAC output
initialDACData = zeros(fs, 1); % Buffer of zeros to start with (length depends on initial session requirements)
queueOutputData(daqSession, initialDACData);
startBackground(daqSession);
disp(‘Press any key to stop’);
pause;
stop(daqSession);
delete(lh);
release(scope);
disp(‘Stopping data acquisition…’);
%% Function to process the signal and update DAC output
function OUT_signal = processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D)
% Input signal from ADC
signal = event.Data;
input_signal = signal(:, 2); % Input signal (from ai1)
dac_signal = signal(:, 1); % Read back the DAC signal (from ai0)
%===MANUAL NUMERICALLY CONTROLLED OSCILLATOR===
t = event.TimeStamps; % Time vector
% Set the control to adjust fc every second
onesec = 0;
tic;
persistent elapsed_time
if isempty(elapsed_time)
elapsed_time = 0;
end
% Update elapsed time
elapsed_time = elapsed_time + t(end) – t(1); % Time since last callback
% When elapsed time exceeds 1 second, update carrier frequency
if elapsed_time >= 1
% Save the current carrier frequency
% Calculate new fc using your control law: fc = fc + Kc * atan(Ik1/Qk1)
fc = fc + Kc * atan(Ik1/Qk1);
% Reset elapsed time
elapsed_time = 0;
onesec = toc;
end
% Generate DAC output
OUT_Signal = 0.5*sin(2*pi*(fc/fs)*t); % Using filtered AM as DAC signal
% Write to DAC (update Analog Output Channel)
src.queueOutputData(OUT_signal);
% Visualization
scope(input_signal, dac_signal, OUT_Signal);
endI am having trouble implementing a real time DAC in my code. I am working with an NI USB-6356 and I have succesfully implemented in my Matlab Code an ADC than reads the real time signal and process it. I am trying to implement a DAC with the DSP tool box (as I did with the ADC) but for some reason it doesn’t work. There aren’t any apparent errors so it is being difficult to solve the problem. Can someone tell me what’s happening?
dev = ‘Dev1’;
channels = {‘ai0’, ‘ai1’};
ao = ‘ao0’; % DAC output channel
fs = 1000; % Sampling Frequency
fc = 10; % Carrier Frequency
fsub = 10; % Subcarrier Frequency
D = 1; % Decimation factor
bits = 16; % DAC Resolution
Kc = 0.01; % Proportional control gain
% Create TimeScope for visualization
scope = timescope(‘NumInputPorts’, 3, ‘TimeSpan’, 2, ‘SampleRate’, fs, …
‘ShowLegend’, true, ‘YLimits’, [-5 5], …
‘Title’, ‘Real-time Signal and Processed Signal’, …
‘ChannelNames’, {‘DAC Output’, ‘Input Signal’, ‘Modulated Signal’});
%% Data Acquisition Setup
daqSession = daq.createSession(‘ni’);
for i = 1:length(channels)
addAnalogInputChannel(daqSession, dev, channels{i}, ‘Voltage’);
end
daqSession.Rate = fs;
daqSession.IsContinuous = true;
addAnalogOutputChannel(daqSession, dev, ao, ‘Voltage’);
% Initialize NCO phase accumulator
nco_phase = 0;
lh = addlistener(daqSession, ‘DataAvailable’, …
@(src, event) processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D));
% Create an initial buffer to queue for DAC output
initialDACData = zeros(fs, 1); % Buffer of zeros to start with (length depends on initial session requirements)
queueOutputData(daqSession, initialDACData);
startBackground(daqSession);
disp(‘Press any key to stop’);
pause;
stop(daqSession);
delete(lh);
release(scope);
disp(‘Stopping data acquisition…’);
%% Function to process the signal and update DAC output
function OUT_signal = processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D)
% Input signal from ADC
signal = event.Data;
input_signal = signal(:, 2); % Input signal (from ai1)
dac_signal = signal(:, 1); % Read back the DAC signal (from ai0)
%===MANUAL NUMERICALLY CONTROLLED OSCILLATOR===
t = event.TimeStamps; % Time vector
% Set the control to adjust fc every second
onesec = 0;
tic;
persistent elapsed_time
if isempty(elapsed_time)
elapsed_time = 0;
end
% Update elapsed time
elapsed_time = elapsed_time + t(end) – t(1); % Time since last callback
% When elapsed time exceeds 1 second, update carrier frequency
if elapsed_time >= 1
% Save the current carrier frequency
% Calculate new fc using your control law: fc = fc + Kc * atan(Ik1/Qk1)
fc = fc + Kc * atan(Ik1/Qk1);
% Reset elapsed time
elapsed_time = 0;
onesec = toc;
end
% Generate DAC output
OUT_Signal = 0.5*sin(2*pi*(fc/fs)*t); % Using filtered AM as DAC signal
% Write to DAC (update Analog Output Channel)
src.queueOutputData(OUT_signal);
% Visualization
scope(input_signal, dac_signal, OUT_Signal);
end I am having trouble implementing a real time DAC in my code. I am working with an NI USB-6356 and I have succesfully implemented in my Matlab Code an ADC than reads the real time signal and process it. I am trying to implement a DAC with the DSP tool box (as I did with the ADC) but for some reason it doesn’t work. There aren’t any apparent errors so it is being difficult to solve the problem. Can someone tell me what’s happening?
dev = ‘Dev1’;
channels = {‘ai0’, ‘ai1’};
ao = ‘ao0’; % DAC output channel
fs = 1000; % Sampling Frequency
fc = 10; % Carrier Frequency
fsub = 10; % Subcarrier Frequency
D = 1; % Decimation factor
bits = 16; % DAC Resolution
Kc = 0.01; % Proportional control gain
% Create TimeScope for visualization
scope = timescope(‘NumInputPorts’, 3, ‘TimeSpan’, 2, ‘SampleRate’, fs, …
‘ShowLegend’, true, ‘YLimits’, [-5 5], …
‘Title’, ‘Real-time Signal and Processed Signal’, …
‘ChannelNames’, {‘DAC Output’, ‘Input Signal’, ‘Modulated Signal’});
%% Data Acquisition Setup
daqSession = daq.createSession(‘ni’);
for i = 1:length(channels)
addAnalogInputChannel(daqSession, dev, channels{i}, ‘Voltage’);
end
daqSession.Rate = fs;
daqSession.IsContinuous = true;
addAnalogOutputChannel(daqSession, dev, ao, ‘Voltage’);
% Initialize NCO phase accumulator
nco_phase = 0;
lh = addlistener(daqSession, ‘DataAvailable’, …
@(src, event) processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D));
% Create an initial buffer to queue for DAC output
initialDACData = zeros(fs, 1); % Buffer of zeros to start with (length depends on initial session requirements)
queueOutputData(daqSession, initialDACData);
startBackground(daqSession);
disp(‘Press any key to stop’);
pause;
stop(daqSession);
delete(lh);
release(scope);
disp(‘Stopping data acquisition…’);
%% Function to process the signal and update DAC output
function OUT_signal = processSignal(src,event, fc, fs, fsub, scope, nco_phase, Kc, D)
% Input signal from ADC
signal = event.Data;
input_signal = signal(:, 2); % Input signal (from ai1)
dac_signal = signal(:, 1); % Read back the DAC signal (from ai0)
%===MANUAL NUMERICALLY CONTROLLED OSCILLATOR===
t = event.TimeStamps; % Time vector
% Set the control to adjust fc every second
onesec = 0;
tic;
persistent elapsed_time
if isempty(elapsed_time)
elapsed_time = 0;
end
% Update elapsed time
elapsed_time = elapsed_time + t(end) – t(1); % Time since last callback
% When elapsed time exceeds 1 second, update carrier frequency
if elapsed_time >= 1
% Save the current carrier frequency
% Calculate new fc using your control law: fc = fc + Kc * atan(Ik1/Qk1)
fc = fc + Kc * atan(Ik1/Qk1);
% Reset elapsed time
elapsed_time = 0;
onesec = toc;
end
% Generate DAC output
OUT_Signal = 0.5*sin(2*pi*(fc/fs)*t); % Using filtered AM as DAC signal
% Write to DAC (update Analog Output Channel)
src.queueOutputData(OUT_signal);
% Visualization
scope(input_signal, dac_signal, OUT_Signal);
end dsp, signal processing, daq, dac MATLAB Answers — New Questions
Discretize in two dimension
I have data points or data co-ordinates in 2D. Let’s say random trajectory for 10000 time steps
x= randn(10000,1);
y= randn(10000,1);
I want to discretize the trajectory in 2D phase space X and Y of equal grids sizes. And then try to calculate the probability fluxes between each grid i.e transition between boxes with time. The transition can be in and out in x or y direction in 2D space.
Any help is appreciated.I have data points or data co-ordinates in 2D. Let’s say random trajectory for 10000 time steps
x= randn(10000,1);
y= randn(10000,1);
I want to discretize the trajectory in 2D phase space X and Y of equal grids sizes. And then try to calculate the probability fluxes between each grid i.e transition between boxes with time. The transition can be in and out in x or y direction in 2D space.
Any help is appreciated. I have data points or data co-ordinates in 2D. Let’s say random trajectory for 10000 time steps
x= randn(10000,1);
y= randn(10000,1);
I want to discretize the trajectory in 2D phase space X and Y of equal grids sizes. And then try to calculate the probability fluxes between each grid i.e transition between boxes with time. The transition can be in and out in x or y direction in 2D space.
Any help is appreciated. matrix, discretize MATLAB Answers — New Questions
Why does the same View property for Axes with different PlotBoxAspectRatio result in different views?
I have two axes, of which I’ve linked the View property. The two have different PlotBoxAspectRatio.
When rotating around in 3D, the two plots behave as I expect. You can overlay the orthogonal axes in the figure below and verify that they are visually aligned:
However, when the plots are rotated into a plane view (elevation = 90°), the same azimuth angle results in a different orientation for each plot:
>> get([a1,a2],’View’)
ans =
2×1 cell array
{[45.2690 90]}
{[45.2690 90]}
The plots will align properly when the axes are horizontal or vertical, but become misaligned in between those states. This only happens for plots with different PlotBoxAspectRatio.
What gives? Code to generate the example above is below:
f = figure(‘Color’, ‘w’); % Figure window
% Coordinates of drawn object
ax1 = [-1.0, +1.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
ax2 = [-2.0, +2.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
% Axes 1
a1 = axes(f, ‘Units’, ‘normalized’, ‘OuterPosition’, [0.0,0.0,0.5,1.0]);
plot3(ax1(1,:),ax1(2,:),ax1(3,:), ‘k’, ‘LineWidth’, 1.0)
axis equal vis3d off
rotate3d on
% Axes 2
a2 = axes(f, ‘Units’, ‘normalized’, ‘OuterPosition’, [0.5,0.0,0.5,1.0]);
plot3(ax2(1,:),ax2(2,:),ax2(3,:), ‘k’, ‘LineWidth’, 1.0)
axis equal vis3d off
rotate3d on
% Link view property
link = linkprop([a1,a2],’View’);
Thanks in advance!I have two axes, of which I’ve linked the View property. The two have different PlotBoxAspectRatio.
When rotating around in 3D, the two plots behave as I expect. You can overlay the orthogonal axes in the figure below and verify that they are visually aligned:
However, when the plots are rotated into a plane view (elevation = 90°), the same azimuth angle results in a different orientation for each plot:
>> get([a1,a2],’View’)
ans =
2×1 cell array
{[45.2690 90]}
{[45.2690 90]}
The plots will align properly when the axes are horizontal or vertical, but become misaligned in between those states. This only happens for plots with different PlotBoxAspectRatio.
What gives? Code to generate the example above is below:
f = figure(‘Color’, ‘w’); % Figure window
% Coordinates of drawn object
ax1 = [-1.0, +1.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
ax2 = [-2.0, +2.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
% Axes 1
a1 = axes(f, ‘Units’, ‘normalized’, ‘OuterPosition’, [0.0,0.0,0.5,1.0]);
plot3(ax1(1,:),ax1(2,:),ax1(3,:), ‘k’, ‘LineWidth’, 1.0)
axis equal vis3d off
rotate3d on
% Axes 2
a2 = axes(f, ‘Units’, ‘normalized’, ‘OuterPosition’, [0.5,0.0,0.5,1.0]);
plot3(ax2(1,:),ax2(2,:),ax2(3,:), ‘k’, ‘LineWidth’, 1.0)
axis equal vis3d off
rotate3d on
% Link view property
link = linkprop([a1,a2],’View’);
Thanks in advance! I have two axes, of which I’ve linked the View property. The two have different PlotBoxAspectRatio.
When rotating around in 3D, the two plots behave as I expect. You can overlay the orthogonal axes in the figure below and verify that they are visually aligned:
However, when the plots are rotated into a plane view (elevation = 90°), the same azimuth angle results in a different orientation for each plot:
>> get([a1,a2],’View’)
ans =
2×1 cell array
{[45.2690 90]}
{[45.2690 90]}
The plots will align properly when the axes are horizontal or vertical, but become misaligned in between those states. This only happens for plots with different PlotBoxAspectRatio.
What gives? Code to generate the example above is below:
f = figure(‘Color’, ‘w’); % Figure window
% Coordinates of drawn object
ax1 = [-1.0, +1.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
ax2 = [-2.0, +2.0, NaN, 0.0, 0.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, -1.0, +1.0, NaN, 0.0, 0.0;
0.0, 0.0, NaN, 0.0, 0.0, NaN, -1.0, +1.0];
% Axes 1
a1 = axes(f, ‘Units’, ‘normalized’, ‘OuterPosition’, [0.0,0.0,0.5,1.0]);
plot3(ax1(1,:),ax1(2,:),ax1(3,:), ‘k’, ‘LineWidth’, 1.0)
axis equal vis3d off
rotate3d on
% Axes 2
a2 = axes(f, ‘Units’, ‘normalized’, ‘OuterPosition’, [0.5,0.0,0.5,1.0]);
plot3(ax2(1,:),ax2(2,:),ax2(3,:), ‘k’, ‘LineWidth’, 1.0)
axis equal vis3d off
rotate3d on
% Link view property
link = linkprop([a1,a2],’View’);
Thanks in advance! figure, axes, 3d plots MATLAB Answers — New Questions
splitting a vector into separate vectors
Hi Matlab community,
I have a vector like
V = [2 2 2 2 2 4 4 4 7 7 8 9]
I want to separate this vector into
V1 = [2 2 2 2 2 ], V2=[4 4 4 ], V3=[7 7 ], V4=8, V5=9
Suppose that I do not know the value in vector V. In each iteration, I have a new vector.
ThanksHi Matlab community,
I have a vector like
V = [2 2 2 2 2 4 4 4 7 7 8 9]
I want to separate this vector into
V1 = [2 2 2 2 2 ], V2=[4 4 4 ], V3=[7 7 ], V4=8, V5=9
Suppose that I do not know the value in vector V. In each iteration, I have a new vector.
Thanks Hi Matlab community,
I have a vector like
V = [2 2 2 2 2 4 4 4 7 7 8 9]
I want to separate this vector into
V1 = [2 2 2 2 2 ], V2=[4 4 4 ], V3=[7 7 ], V4=8, V5=9
Suppose that I do not know the value in vector V. In each iteration, I have a new vector.
Thanks matrix MATLAB Answers — New Questions
Choose any workspace from dbstack for evalin
I wrote an App to add lines to axes. I need to pass some variables from the workspace where this App is called to the private handling function of this App.
function demoFcn()
fs = 20e3;
t = 1/fs:1/fs:1;
f = 100;
figure;
subplot(1, 2, 1);
plot(t, cos(2*pi*f*t));
% call drawLineApp to specify X and Y for extra lines in this axes
drawLineApp(gca);
end
For example, after finishing drawing some lines, I call this to draw in the existed subplot and I have two input text box in my App for x and y, where x=t and y=sin(2*pi*f*t). Both f and t are existed variables in the workspace of the drawing function (indeed, the drawing is not done in the base workspace). If I use:
methods (Access = private)
function drawButtonPushed(app, event) % button callback function
drawLineImpl(app);
end
function drawLineImpl(app)
% app.X is string "t" from the input text box
% app.Y is string "sin(2*pi*f*t)"
% app.target is the target axes to plot
% app.params is the plotting parameter cell array
X = evalin("caller", app.X);
Y = evalin("caller", app.Y);
plot(app.target, X, Y, app.params{:});
end
end
I would not get the desired result because ‘caller’ does not point to demoFcn().
So I want to track in the function stack where drawLineApp() is last called using dbstack. But evalin specifies workspace only with options ‘base’ and ‘caller’. It comes to me whether I can specify any workspace found in the dbstack here.
By the way, I know that dbup can change the current workspace but only in debug mode. It does not work well in my case.I wrote an App to add lines to axes. I need to pass some variables from the workspace where this App is called to the private handling function of this App.
function demoFcn()
fs = 20e3;
t = 1/fs:1/fs:1;
f = 100;
figure;
subplot(1, 2, 1);
plot(t, cos(2*pi*f*t));
% call drawLineApp to specify X and Y for extra lines in this axes
drawLineApp(gca);
end
For example, after finishing drawing some lines, I call this to draw in the existed subplot and I have two input text box in my App for x and y, where x=t and y=sin(2*pi*f*t). Both f and t are existed variables in the workspace of the drawing function (indeed, the drawing is not done in the base workspace). If I use:
methods (Access = private)
function drawButtonPushed(app, event) % button callback function
drawLineImpl(app);
end
function drawLineImpl(app)
% app.X is string "t" from the input text box
% app.Y is string "sin(2*pi*f*t)"
% app.target is the target axes to plot
% app.params is the plotting parameter cell array
X = evalin("caller", app.X);
Y = evalin("caller", app.Y);
plot(app.target, X, Y, app.params{:});
end
end
I would not get the desired result because ‘caller’ does not point to demoFcn().
So I want to track in the function stack where drawLineApp() is last called using dbstack. But evalin specifies workspace only with options ‘base’ and ‘caller’. It comes to me whether I can specify any workspace found in the dbstack here.
By the way, I know that dbup can change the current workspace but only in debug mode. It does not work well in my case. I wrote an App to add lines to axes. I need to pass some variables from the workspace where this App is called to the private handling function of this App.
function demoFcn()
fs = 20e3;
t = 1/fs:1/fs:1;
f = 100;
figure;
subplot(1, 2, 1);
plot(t, cos(2*pi*f*t));
% call drawLineApp to specify X and Y for extra lines in this axes
drawLineApp(gca);
end
For example, after finishing drawing some lines, I call this to draw in the existed subplot and I have two input text box in my App for x and y, where x=t and y=sin(2*pi*f*t). Both f and t are existed variables in the workspace of the drawing function (indeed, the drawing is not done in the base workspace). If I use:
methods (Access = private)
function drawButtonPushed(app, event) % button callback function
drawLineImpl(app);
end
function drawLineImpl(app)
% app.X is string "t" from the input text box
% app.Y is string "sin(2*pi*f*t)"
% app.target is the target axes to plot
% app.params is the plotting parameter cell array
X = evalin("caller", app.X);
Y = evalin("caller", app.Y);
plot(app.target, X, Y, app.params{:});
end
end
I would not get the desired result because ‘caller’ does not point to demoFcn().
So I want to track in the function stack where drawLineApp() is last called using dbstack. But evalin specifies workspace only with options ‘base’ and ‘caller’. It comes to me whether I can specify any workspace found in the dbstack here.
By the way, I know that dbup can change the current workspace but only in debug mode. It does not work well in my case. evalin, workspace, dbstack MATLAB Answers — New Questions
Alternative to scatter3 plot
i often need to display X,Y,Z Data which are colored.
So far, i use
figure;
scatter3 (X,Y,Z, DotSize ,Z) ;
which delivers the desired result and is a single line of code (easy to remeber and usable on many different computers without implementing own stuff every time)
But the resulting graphs are very (and sometimes extremely) slow in reaction.
Even closing the graph is very slow.
A more potent graphic card does not have the slightest effect on that.
Is there another way to display X,Y,Z data colored and more efficient ?
Of course, i can use plot3, but then the data are not colored.
thxi often need to display X,Y,Z Data which are colored.
So far, i use
figure;
scatter3 (X,Y,Z, DotSize ,Z) ;
which delivers the desired result and is a single line of code (easy to remeber and usable on many different computers without implementing own stuff every time)
But the resulting graphs are very (and sometimes extremely) slow in reaction.
Even closing the graph is very slow.
A more potent graphic card does not have the slightest effect on that.
Is there another way to display X,Y,Z data colored and more efficient ?
Of course, i can use plot3, but then the data are not colored.
thx i often need to display X,Y,Z Data which are colored.
So far, i use
figure;
scatter3 (X,Y,Z, DotSize ,Z) ;
which delivers the desired result and is a single line of code (easy to remeber and usable on many different computers without implementing own stuff every time)
But the resulting graphs are very (and sometimes extremely) slow in reaction.
Even closing the graph is very slow.
A more potent graphic card does not have the slightest effect on that.
Is there another way to display X,Y,Z data colored and more efficient ?
Of course, i can use plot3, but then the data are not colored.
thx scatter3, data display, plot vector data MATLAB Answers — New Questions
conformal mapping of circle
how can I transform a circle to ellipse or airfoil in complex plane using conformal mapping and w = z + 1/z transform function?how can I transform a circle to ellipse or airfoil in complex plane using conformal mapping and w = z + 1/z transform function? how can I transform a circle to ellipse or airfoil in complex plane using conformal mapping and w = z + 1/z transform function? circle to ellipse transformation MATLAB Answers — New Questions
Regarding the C2000 blockset, how would I have one SPI block transmit right after another SPI block?
Hello all,
I need to send 32 bits of data to an external DAC via a microcontroller. The SPI blocks given in the C2000 blockset can only send a maximum of 16 bits. How would I go about sending 16 bits of data right after another 16 bits of data without the CS going high in between.
Thank you in advance.Hello all,
I need to send 32 bits of data to an external DAC via a microcontroller. The SPI blocks given in the C2000 blockset can only send a maximum of 16 bits. How would I go about sending 16 bits of data right after another 16 bits of data without the CS going high in between.
Thank you in advance. Hello all,
I need to send 32 bits of data to an external DAC via a microcontroller. The SPI blocks given in the C2000 blockset can only send a maximum of 16 bits. How would I go about sending 16 bits of data right after another 16 bits of data without the CS going high in between.
Thank you in advance. spi, c200, code generation, simulink MATLAB Answers — New Questions
Using Runge Kutta to solve second-order differential equations with two degrees of freedom
Hi everyone, I am beginner in Matlab Programming,I have been trying to solve the differential equation system given below, but I am unable to establish a workflow. Any assistance or related work would be greatly appreciated. Thanks in advance.
In the following system of differential equations, x and xb are structural responses, omga is frequency ratio, tau is time, and other parameters are constants. The requirement is that we need to provide the relationship between the structural response of the system and the frequency ratio omga.
matlab program:
function [T,X,dX] = ODE_RK4( Hfun,t,h,x0 )
if nargin < 4
error(‘The initial value must be given’);
end
if isstr(Hfun)
eval([‘Hfun = @’,Hfun,’;’]);
end
n = length(t);
if n == 1
T = 0:h:t;
elseif n == 2
T = t(1):h:t(2);
else
T = t;
end
T = T(:);
N = length(T);
x0 = x0(:);
x0 = x0′;
m = length(x0);
X = zeros(N,m);
dX = zeros(N,m);
X(1,:) = x0;
for k = 2:N
h = T(k) – T(k-1);
K1 = Hfun( T(k-1) , X(k-1,:)’ );
K2 = Hfun( T(k-1)+h/2 , X(k-1,:)’+h*K1/2 );
K3 = Hfun( T(k-1)+h/2 , X(k-1,:)’+h*K2/2 );
K4 = Hfun( T(k-1)+h , X(k-1,:)’+h*K3 );
X(k,:) = X(k-1,:)’ + (h/6) * ( K1 + 2*K2 + 2*K3 + K4 );
dX(k-1,:) = (1/6) * ( K1 + 2*K2 + 2*K3 + K4 );
end
dX(N,:) = Hfun( T(N),X(N,:) );
if nargout == 0
plot(T,X)
end
clc;
clear;
lambda_b = 0.01;
lambda_ns = -0.01;
lambda = 0.5;
zeta_b = 0.025;
chi = 0.0001;
alpha = 0.2;
zeta = 0.05;
z = 0.06;
omega_values = linspace(0.05, 1, 1000);
tau = linspace(0, 2*pi, 1000);
dt = tau(2) – tau(1);
X0 = [0; 0; 0; 0]; % Initial value
x_max = zeros(1, length(omega_values));
for i = 1:length(omega_values)
omega = omega_values(i);
f = @(t, X) [X(2);
-(2*zeta*omega*X(2) + 4*(2*alpha^2*X(1)^3*lambda+1/sqrt(alpha)) + lambda_b*(X(1) – X(3)) + z*cos(t)) / omega^2;
X(4);
-1/(chi*omega^2)*(2*zeta_b*omega*X(4) + lambda_ns*X(3) – lambda_b*(X(1) – X(3)))];
[T,X]= ODE_RK4(f, tau, dt,X0);
x_max(i) = max(abs(X(i, :)));
end
figure;
plot(omega_values, x_max);
xlabel(‘omega’);
ylabel(‘x_{max}’);Hi everyone, I am beginner in Matlab Programming,I have been trying to solve the differential equation system given below, but I am unable to establish a workflow. Any assistance or related work would be greatly appreciated. Thanks in advance.
In the following system of differential equations, x and xb are structural responses, omga is frequency ratio, tau is time, and other parameters are constants. The requirement is that we need to provide the relationship between the structural response of the system and the frequency ratio omga.
matlab program:
function [T,X,dX] = ODE_RK4( Hfun,t,h,x0 )
if nargin < 4
error(‘The initial value must be given’);
end
if isstr(Hfun)
eval([‘Hfun = @’,Hfun,’;’]);
end
n = length(t);
if n == 1
T = 0:h:t;
elseif n == 2
T = t(1):h:t(2);
else
T = t;
end
T = T(:);
N = length(T);
x0 = x0(:);
x0 = x0′;
m = length(x0);
X = zeros(N,m);
dX = zeros(N,m);
X(1,:) = x0;
for k = 2:N
h = T(k) – T(k-1);
K1 = Hfun( T(k-1) , X(k-1,:)’ );
K2 = Hfun( T(k-1)+h/2 , X(k-1,:)’+h*K1/2 );
K3 = Hfun( T(k-1)+h/2 , X(k-1,:)’+h*K2/2 );
K4 = Hfun( T(k-1)+h , X(k-1,:)’+h*K3 );
X(k,:) = X(k-1,:)’ + (h/6) * ( K1 + 2*K2 + 2*K3 + K4 );
dX(k-1,:) = (1/6) * ( K1 + 2*K2 + 2*K3 + K4 );
end
dX(N,:) = Hfun( T(N),X(N,:) );
if nargout == 0
plot(T,X)
end
clc;
clear;
lambda_b = 0.01;
lambda_ns = -0.01;
lambda = 0.5;
zeta_b = 0.025;
chi = 0.0001;
alpha = 0.2;
zeta = 0.05;
z = 0.06;
omega_values = linspace(0.05, 1, 1000);
tau = linspace(0, 2*pi, 1000);
dt = tau(2) – tau(1);
X0 = [0; 0; 0; 0]; % Initial value
x_max = zeros(1, length(omega_values));
for i = 1:length(omega_values)
omega = omega_values(i);
f = @(t, X) [X(2);
-(2*zeta*omega*X(2) + 4*(2*alpha^2*X(1)^3*lambda+1/sqrt(alpha)) + lambda_b*(X(1) – X(3)) + z*cos(t)) / omega^2;
X(4);
-1/(chi*omega^2)*(2*zeta_b*omega*X(4) + lambda_ns*X(3) – lambda_b*(X(1) – X(3)))];
[T,X]= ODE_RK4(f, tau, dt,X0);
x_max(i) = max(abs(X(i, :)));
end
figure;
plot(omega_values, x_max);
xlabel(‘omega’);
ylabel(‘x_{max}’); Hi everyone, I am beginner in Matlab Programming,I have been trying to solve the differential equation system given below, but I am unable to establish a workflow. Any assistance or related work would be greatly appreciated. Thanks in advance.
In the following system of differential equations, x and xb are structural responses, omga is frequency ratio, tau is time, and other parameters are constants. The requirement is that we need to provide the relationship between the structural response of the system and the frequency ratio omga.
matlab program:
function [T,X,dX] = ODE_RK4( Hfun,t,h,x0 )
if nargin < 4
error(‘The initial value must be given’);
end
if isstr(Hfun)
eval([‘Hfun = @’,Hfun,’;’]);
end
n = length(t);
if n == 1
T = 0:h:t;
elseif n == 2
T = t(1):h:t(2);
else
T = t;
end
T = T(:);
N = length(T);
x0 = x0(:);
x0 = x0′;
m = length(x0);
X = zeros(N,m);
dX = zeros(N,m);
X(1,:) = x0;
for k = 2:N
h = T(k) – T(k-1);
K1 = Hfun( T(k-1) , X(k-1,:)’ );
K2 = Hfun( T(k-1)+h/2 , X(k-1,:)’+h*K1/2 );
K3 = Hfun( T(k-1)+h/2 , X(k-1,:)’+h*K2/2 );
K4 = Hfun( T(k-1)+h , X(k-1,:)’+h*K3 );
X(k,:) = X(k-1,:)’ + (h/6) * ( K1 + 2*K2 + 2*K3 + K4 );
dX(k-1,:) = (1/6) * ( K1 + 2*K2 + 2*K3 + K4 );
end
dX(N,:) = Hfun( T(N),X(N,:) );
if nargout == 0
plot(T,X)
end
clc;
clear;
lambda_b = 0.01;
lambda_ns = -0.01;
lambda = 0.5;
zeta_b = 0.025;
chi = 0.0001;
alpha = 0.2;
zeta = 0.05;
z = 0.06;
omega_values = linspace(0.05, 1, 1000);
tau = linspace(0, 2*pi, 1000);
dt = tau(2) – tau(1);
X0 = [0; 0; 0; 0]; % Initial value
x_max = zeros(1, length(omega_values));
for i = 1:length(omega_values)
omega = omega_values(i);
f = @(t, X) [X(2);
-(2*zeta*omega*X(2) + 4*(2*alpha^2*X(1)^3*lambda+1/sqrt(alpha)) + lambda_b*(X(1) – X(3)) + z*cos(t)) / omega^2;
X(4);
-1/(chi*omega^2)*(2*zeta_b*omega*X(4) + lambda_ns*X(3) – lambda_b*(X(1) – X(3)))];
[T,X]= ODE_RK4(f, tau, dt,X0);
x_max(i) = max(abs(X(i, :)));
end
figure;
plot(omega_values, x_max);
xlabel(‘omega’);
ylabel(‘x_{max}’); runge-kutta, matlab MATLAB Answers — New Questions
Flow field over a flat plate airfoil
I would like to plot a velocity field over a flate plate airfoil inclined at an angle of attack alpha (alpha = 5°).
The velocity is defined by the Mach numbber being 5. The air is considerate as an ideal gas, and at sea level.
The dimension of the airfoil are (2D):
chord length = 1m
height = 0.05m
I also would like to have a CFD solution
Tell me if there are missing informations.
Thank you in advanceI would like to plot a velocity field over a flate plate airfoil inclined at an angle of attack alpha (alpha = 5°).
The velocity is defined by the Mach numbber being 5. The air is considerate as an ideal gas, and at sea level.
The dimension of the airfoil are (2D):
chord length = 1m
height = 0.05m
I also would like to have a CFD solution
Tell me if there are missing informations.
Thank you in advance I would like to plot a velocity field over a flate plate airfoil inclined at an angle of attack alpha (alpha = 5°).
The velocity is defined by the Mach numbber being 5. The air is considerate as an ideal gas, and at sea level.
The dimension of the airfoil are (2D):
chord length = 1m
height = 0.05m
I also would like to have a CFD solution
Tell me if there are missing informations.
Thank you in advance homework, compressible flow, cfd MATLAB Answers — New Questions
How to import result data from OpenFOAM to matlab?
hello,
I want to import the result data from OpenFOAM which are compressed to matlab to plot the results and compare them with the results of other flow models. Can anyone please help me with the code?
Regards,
Mahendrahello,
I want to import the result data from OpenFOAM which are compressed to matlab to plot the results and compare them with the results of other flow models. Can anyone please help me with the code?
Regards,
Mahendra hello,
I want to import the result data from OpenFOAM which are compressed to matlab to plot the results and compare them with the results of other flow models. Can anyone please help me with the code?
Regards,
Mahendra data import, zip file import, data import fromopenfoam to matlab MATLAB Answers — New Questions
Integrating Simulink with OpenFOAM.
Is there any way of integrating Simulink with OpenFOAM (e.g. having an engine model in the first and a propeller model in the second)?Is there any way of integrating Simulink with OpenFOAM (e.g. having an engine model in the first and a propeller model in the second)? Is there any way of integrating Simulink with OpenFOAM (e.g. having an engine model in the first and a propeller model in the second)? simulink, openfoam, integration, matlab, communication MATLAB Answers — New Questions
Why do I receive a privimporthdl error when importing the operator.vhd example
Hello,
I am trying to import a VHDL file using the operator.vhd example. However, I receive the following error when using the importhdl function.
I beleive I have followed the example correctly, but I am at a loss as to why this is occuring. Is this a problem experienced by others at all? I’m not sure what I can try next.
Below is the operator.vhd code when it is opened within the MATLAB editor.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Operator is
Port ( A : in STD_LOGIC_VECTOR(3 downto 0);
B : in STD_LOGIC_VECTOR(3 downto 0);
OpSelect : in STD_LOGIC_VECTOR(2 downto 0);
Result : out STD_LOGIC_VECTOR(3 downto 0));
end Operator;
architecture Behavioral of Operator is
begin
process(A, B, OpSelect)
begin
case OpSelect is
when "000" => — Addition
Result <= A + B;
when "001" => — Subtraction
Result <= A – B;
when "010" => — Bitwise AND
Result <= A and B;
when "011" => — Bitwise OR
Result <= A or B;
when "100" => — Bitwise XOR
Result <= A xor B;
when others => — Default case
Result <= not (A + B);
end case;
end process;
end Behavioral;Hello,
I am trying to import a VHDL file using the operator.vhd example. However, I receive the following error when using the importhdl function.
I beleive I have followed the example correctly, but I am at a loss as to why this is occuring. Is this a problem experienced by others at all? I’m not sure what I can try next.
Below is the operator.vhd code when it is opened within the MATLAB editor.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Operator is
Port ( A : in STD_LOGIC_VECTOR(3 downto 0);
B : in STD_LOGIC_VECTOR(3 downto 0);
OpSelect : in STD_LOGIC_VECTOR(2 downto 0);
Result : out STD_LOGIC_VECTOR(3 downto 0));
end Operator;
architecture Behavioral of Operator is
begin
process(A, B, OpSelect)
begin
case OpSelect is
when "000" => — Addition
Result <= A + B;
when "001" => — Subtraction
Result <= A – B;
when "010" => — Bitwise AND
Result <= A and B;
when "011" => — Bitwise OR
Result <= A or B;
when "100" => — Bitwise XOR
Result <= A xor B;
when others => — Default case
Result <= not (A + B);
end case;
end process;
end Behavioral; Hello,
I am trying to import a VHDL file using the operator.vhd example. However, I receive the following error when using the importhdl function.
I beleive I have followed the example correctly, but I am at a loss as to why this is occuring. Is this a problem experienced by others at all? I’m not sure what I can try next.
Below is the operator.vhd code when it is opened within the MATLAB editor.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Operator is
Port ( A : in STD_LOGIC_VECTOR(3 downto 0);
B : in STD_LOGIC_VECTOR(3 downto 0);
OpSelect : in STD_LOGIC_VECTOR(2 downto 0);
Result : out STD_LOGIC_VECTOR(3 downto 0));
end Operator;
architecture Behavioral of Operator is
begin
process(A, B, OpSelect)
begin
case OpSelect is
when "000" => — Addition
Result <= A + B;
when "001" => — Subtraction
Result <= A – B;
when "010" => — Bitwise AND
Result <= A and B;
when "011" => — Bitwise OR
Result <= A or B;
when "100" => — Bitwise XOR
Result <= A xor B;
when others => — Default case
Result <= not (A + B);
end case;
end process;
end Behavioral; importhdl MATLAB Answers — New Questions
MATLAB ANALYSIS run Successfully on ThingSpeak, BUT always generates Server Error 500, so doesn’t send email
The error is:
"Failed to send alert: The server returned the status 500 with message "Internal Server Error" in response to the request to URL https://api.thingspeak.com/alerts/send."
The message says MATLAB Analysis ran successfully, so the code is good, but never sends the email because of the server error.
Simple code from examples:
% Catch errors so the MATLAB code does not disable a TimeControl if it fails
try
webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options);
catch someException
fprintf("Failed to send alert: %sn", someException.message);
end
Where to go from here?The error is:
"Failed to send alert: The server returned the status 500 with message "Internal Server Error" in response to the request to URL https://api.thingspeak.com/alerts/send."
The message says MATLAB Analysis ran successfully, so the code is good, but never sends the email because of the server error.
Simple code from examples:
% Catch errors so the MATLAB code does not disable a TimeControl if it fails
try
webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options);
catch someException
fprintf("Failed to send alert: %sn", someException.message);
end
Where to go from here? The error is:
"Failed to send alert: The server returned the status 500 with message "Internal Server Error" in response to the request to URL https://api.thingspeak.com/alerts/send."
The message says MATLAB Analysis ran successfully, so the code is good, but never sends the email because of the server error.
Simple code from examples:
% Catch errors so the MATLAB code does not disable a TimeControl if it fails
try
webwrite(alertUrl , "body", alertBody, "subject", alertSubject, options);
catch someException
fprintf("Failed to send alert: %sn", someException.message);
end
Where to go from here? thingspeak MATLAB Answers — New Questions
Hi, does anyone know how to generate the graph as shown below based on a torus? Thank you so much.
Post Content Post Content torus MATLAB Answers — New Questions
For loop won’t display all 10 images in the subplot
%% 1.1 – Load and Prepare Data Set
clear;
clc;
B = load(‘images.mat’).image_data’; % Loads image file and transposes
C = mat2gray(B); % Converts images to grayscale
% Loop to generate and display images
for i = 1:10
im = reshape(C(:,i), [37, 50])’; % Reshape and store the image
subplot(10, 1, i); % Create a 10×1 grid of subplots
imshow(im, []); % Display each image with scaling
end
The above turns the colunms of a correctly sized matrix into images. When run I’m only getting 9 images of the neccessary 10. I’m thinking there’s some quirk where the firs column isn’t running but I’m unsure. I’m running it in matlab live in a browser window.%% 1.1 – Load and Prepare Data Set
clear;
clc;
B = load(‘images.mat’).image_data’; % Loads image file and transposes
C = mat2gray(B); % Converts images to grayscale
% Loop to generate and display images
for i = 1:10
im = reshape(C(:,i), [37, 50])’; % Reshape and store the image
subplot(10, 1, i); % Create a 10×1 grid of subplots
imshow(im, []); % Display each image with scaling
end
The above turns the colunms of a correctly sized matrix into images. When run I’m only getting 9 images of the neccessary 10. I’m thinking there’s some quirk where the firs column isn’t running but I’m unsure. I’m running it in matlab live in a browser window. %% 1.1 – Load and Prepare Data Set
clear;
clc;
B = load(‘images.mat’).image_data’; % Loads image file and transposes
C = mat2gray(B); % Converts images to grayscale
% Loop to generate and display images
for i = 1:10
im = reshape(C(:,i), [37, 50])’; % Reshape and store the image
subplot(10, 1, i); % Create a 10×1 grid of subplots
imshow(im, []); % Display each image with scaling
end
The above turns the colunms of a correctly sized matrix into images. When run I’m only getting 9 images of the neccessary 10. I’m thinking there’s some quirk where the firs column isn’t running but I’m unsure. I’m running it in matlab live in a browser window. for loop MATLAB Answers — New Questions