Category: Matlab
Category Archives: Matlab
Why am I receiving errors when reading and writing to an instrument with Instrument Control Toolbox R2024b?
I am connecting to my Windows 11 based Keysight oscilloscope and source via "visadev." I intermittently receive the following two errors when reading and writing to the instruments using "fscanf" and "fprintf":
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fprintf (line 140)
Error writing String.
Error writing data to the transport.
Adaptor command ‘write’ failed with status code: -550.
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fscanf (line 305)
Failed to read data from the instrument due to a driver error.
These errors occur seemingly at random, and a similar error occurs when using the function "visa" instead of "visadev":
Error using icinterface/fprintf (line 158)
VISA: The IO connection for the session has been lost
Why do these errors occur and how can I prevent them?I am connecting to my Windows 11 based Keysight oscilloscope and source via "visadev." I intermittently receive the following two errors when reading and writing to the instruments using "fscanf" and "fprintf":
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fprintf (line 140)
Error writing String.
Error writing data to the transport.
Adaptor command ‘write’ failed with status code: -550.
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fscanf (line 305)
Failed to read data from the instrument due to a driver error.
These errors occur seemingly at random, and a similar error occurs when using the function "visa" instead of "visadev":
Error using icinterface/fprintf (line 158)
VISA: The IO connection for the session has been lost
Why do these errors occur and how can I prevent them? I am connecting to my Windows 11 based Keysight oscilloscope and source via "visadev." I intermittently receive the following two errors when reading and writing to the instruments using "fscanf" and "fprintf":
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fprintf (line 140)
Error writing String.
Error writing data to the transport.
Adaptor command ‘write’ failed with status code: -550.
Error using matlabshared.transportlib.internal.compatibility.LegacyASCIIMixin/fscanf (line 305)
Failed to read data from the instrument due to a driver error.
These errors occur seemingly at random, and a similar error occurs when using the function "visa" instead of "visadev":
Error using icinterface/fprintf (line 158)
VISA: The IO connection for the session has been lost
Why do these errors occur and how can I prevent them? fprintf, fscanf, instrumentcontroltoolbox, write, read MATLAB Answers — New Questions
How do I compute bandpower?
Which parts of this code is correct? I’m getting confused on which sections are relevant for my question above?
N = length(sig1);
xdft1 = fft(sig1);
xdft1 = xdft1(1:N/2+1);
psdx1 = (1/(Fs*N)) * abs(xdft1).^2;
psdx1(2:end-1) = 2*psdx1(2:end-1);
freq1 = 0:Fs/length(sig1):Fs/2;
P1_band = psdx1(freq1 >= 20 & freq1 <= 100);
f1_band = freq1(freq1 >= 20 & freq1 <= 100);
power_sig1 = trapz(f1_band, P1_band);
noise = x_new – x_notch;
SNR_dB = snr(x_notch, noise);
P_signal = mean(signalSeg.^2, ‘omitnan’);
P_noise = mean(noiseSeg.^2, ‘omitnan’);
SNR_dB = 10*log10(P_signal / P_noise);
f_notch = 60;
BW_notch = 2;
wo = f_notch/(Fs/2);
Q = f_notch/BW_notch;
bw = wo/Q;
[b_n,a_n] = iirnotch(wo,bw);
x_notch = filtfilt(b_n,a_n,x_bp);
x = x(:);
t = (0:length(x)-1)’/Fs;
% Frequency analysis
x_dm = x – mean(x);
N = length(x_dm);
X = fft(x_dm);
K = floor(N/2);
X = X(1:K+1);
PSD = (1/(Fs*N)) * abs(X).^2;
if K > 1
PSD(2:end-1) = 2*PSD(2:end-1);
end
f = (0:K)’ * (Fs/N);
% Find dominant frequency
[~, idxPeak] = max(PSD(2:end)); % ignore 0 Hz
idxPeak = idxPeak + 1;
domFreq = f(idxPeak);
fprintf(‘Dominant frequency = %.2f Hzn’, domFreq);Which parts of this code is correct? I’m getting confused on which sections are relevant for my question above?
N = length(sig1);
xdft1 = fft(sig1);
xdft1 = xdft1(1:N/2+1);
psdx1 = (1/(Fs*N)) * abs(xdft1).^2;
psdx1(2:end-1) = 2*psdx1(2:end-1);
freq1 = 0:Fs/length(sig1):Fs/2;
P1_band = psdx1(freq1 >= 20 & freq1 <= 100);
f1_band = freq1(freq1 >= 20 & freq1 <= 100);
power_sig1 = trapz(f1_band, P1_band);
noise = x_new – x_notch;
SNR_dB = snr(x_notch, noise);
P_signal = mean(signalSeg.^2, ‘omitnan’);
P_noise = mean(noiseSeg.^2, ‘omitnan’);
SNR_dB = 10*log10(P_signal / P_noise);
f_notch = 60;
BW_notch = 2;
wo = f_notch/(Fs/2);
Q = f_notch/BW_notch;
bw = wo/Q;
[b_n,a_n] = iirnotch(wo,bw);
x_notch = filtfilt(b_n,a_n,x_bp);
x = x(:);
t = (0:length(x)-1)’/Fs;
% Frequency analysis
x_dm = x – mean(x);
N = length(x_dm);
X = fft(x_dm);
K = floor(N/2);
X = X(1:K+1);
PSD = (1/(Fs*N)) * abs(X).^2;
if K > 1
PSD(2:end-1) = 2*PSD(2:end-1);
end
f = (0:K)’ * (Fs/N);
% Find dominant frequency
[~, idxPeak] = max(PSD(2:end)); % ignore 0 Hz
idxPeak = idxPeak + 1;
domFreq = f(idxPeak);
fprintf(‘Dominant frequency = %.2f Hzn’, domFreq); Which parts of this code is correct? I’m getting confused on which sections are relevant for my question above?
N = length(sig1);
xdft1 = fft(sig1);
xdft1 = xdft1(1:N/2+1);
psdx1 = (1/(Fs*N)) * abs(xdft1).^2;
psdx1(2:end-1) = 2*psdx1(2:end-1);
freq1 = 0:Fs/length(sig1):Fs/2;
P1_band = psdx1(freq1 >= 20 & freq1 <= 100);
f1_band = freq1(freq1 >= 20 & freq1 <= 100);
power_sig1 = trapz(f1_band, P1_band);
noise = x_new – x_notch;
SNR_dB = snr(x_notch, noise);
P_signal = mean(signalSeg.^2, ‘omitnan’);
P_noise = mean(noiseSeg.^2, ‘omitnan’);
SNR_dB = 10*log10(P_signal / P_noise);
f_notch = 60;
BW_notch = 2;
wo = f_notch/(Fs/2);
Q = f_notch/BW_notch;
bw = wo/Q;
[b_n,a_n] = iirnotch(wo,bw);
x_notch = filtfilt(b_n,a_n,x_bp);
x = x(:);
t = (0:length(x)-1)’/Fs;
% Frequency analysis
x_dm = x – mean(x);
N = length(x_dm);
X = fft(x_dm);
K = floor(N/2);
X = X(1:K+1);
PSD = (1/(Fs*N)) * abs(X).^2;
if K > 1
PSD(2:end-1) = 2*PSD(2:end-1);
end
f = (0:K)’ * (Fs/N);
% Find dominant frequency
[~, idxPeak] = max(PSD(2:end)); % ignore 0 Hz
idxPeak = idxPeak + 1;
domFreq = f(idxPeak);
fprintf(‘Dominant frequency = %.2f Hzn’, domFreq); bandpower MATLAB Answers — New Questions
Need to download MATLAB 2008b onto my existing computer but no more activations exist for my license
My company (MITRE) has implemented CyberArk security that prevents me from accessing MATLAB on my C: drive. I needed to transfer MATLAB over to my personal folder but inorder to do this, I had to uninstall MATLAB. Unfortunately, when I try to reinstall MATLAB 2008b, it says I have no further activations on the license. This is the same computer that I have been using — I have not changed computers. I needed a similar license refresh a couple of years ago when a security breach resulted in scrubing the disk, prompting me to reinstall all of my former software including MATLAB. Please advise — I really rely on this software for my work.
Thank youMy company (MITRE) has implemented CyberArk security that prevents me from accessing MATLAB on my C: drive. I needed to transfer MATLAB over to my personal folder but inorder to do this, I had to uninstall MATLAB. Unfortunately, when I try to reinstall MATLAB 2008b, it says I have no further activations on the license. This is the same computer that I have been using — I have not changed computers. I needed a similar license refresh a couple of years ago when a security breach resulted in scrubing the disk, prompting me to reinstall all of my former software including MATLAB. Please advise — I really rely on this software for my work.
Thank you My company (MITRE) has implemented CyberArk security that prevents me from accessing MATLAB on my C: drive. I needed to transfer MATLAB over to my personal folder but inorder to do this, I had to uninstall MATLAB. Unfortunately, when I try to reinstall MATLAB 2008b, it says I have no further activations on the license. This is the same computer that I have been using — I have not changed computers. I needed a similar license refresh a couple of years ago when a security breach resulted in scrubing the disk, prompting me to reinstall all of my former software including MATLAB. Please advise — I really rely on this software for my work.
Thank you license activation MATLAB Answers — New Questions
How to use the nonlinear least square fitting to fit a transfer function?How to improve the fitting accuracy
I have a dataset Y representing the real part Y(:,1) and the imaginary part (Y:,2) of a function against the frequency fq. I want to find the coefficient of the transfer function to have the a good fit with the dataset. The transfer function is given assumed to have a fifth order, (so there are totally 10 unknowns) T(p,q,s)=p(5)*s^4+p(4)*s^3+p(3)*s^2+p(2)*s+p(1))/(s^5+q(5)*s^4+q(4)*s^3+q(3)*s^2+q(2)*s+q(1));
The code is given in the attached, I split the objective function as the imaginary and real part respectively, the objective function is (real(T)-Y(:,1))^2+(imag(T)-Y(:,2)) over all the selected points in the Y-fq curve.
The blue circle is the fitted result from the NLSQ, but they are slightly away from the original data. My question is how to improve the code to improve the fitting result.
In the attached files,"nonlsqfitting.mat" is the Y and fq data; NLSFmat is the runing code; OBJrealimag.m is the objective function, where Yout(:,1) is the real part of T and Yout(:,2) is the imaginary part of T.I have a dataset Y representing the real part Y(:,1) and the imaginary part (Y:,2) of a function against the frequency fq. I want to find the coefficient of the transfer function to have the a good fit with the dataset. The transfer function is given assumed to have a fifth order, (so there are totally 10 unknowns) T(p,q,s)=p(5)*s^4+p(4)*s^3+p(3)*s^2+p(2)*s+p(1))/(s^5+q(5)*s^4+q(4)*s^3+q(3)*s^2+q(2)*s+q(1));
The code is given in the attached, I split the objective function as the imaginary and real part respectively, the objective function is (real(T)-Y(:,1))^2+(imag(T)-Y(:,2)) over all the selected points in the Y-fq curve.
The blue circle is the fitted result from the NLSQ, but they are slightly away from the original data. My question is how to improve the code to improve the fitting result.
In the attached files,"nonlsqfitting.mat" is the Y and fq data; NLSFmat is the runing code; OBJrealimag.m is the objective function, where Yout(:,1) is the real part of T and Yout(:,2) is the imaginary part of T. I have a dataset Y representing the real part Y(:,1) and the imaginary part (Y:,2) of a function against the frequency fq. I want to find the coefficient of the transfer function to have the a good fit with the dataset. The transfer function is given assumed to have a fifth order, (so there are totally 10 unknowns) T(p,q,s)=p(5)*s^4+p(4)*s^3+p(3)*s^2+p(2)*s+p(1))/(s^5+q(5)*s^4+q(4)*s^3+q(3)*s^2+q(2)*s+q(1));
The code is given in the attached, I split the objective function as the imaginary and real part respectively, the objective function is (real(T)-Y(:,1))^2+(imag(T)-Y(:,2)) over all the selected points in the Y-fq curve.
The blue circle is the fitted result from the NLSQ, but they are slightly away from the original data. My question is how to improve the code to improve the fitting result.
In the attached files,"nonlsqfitting.mat" is the Y and fq data; NLSFmat is the runing code; OBJrealimag.m is the objective function, where Yout(:,1) is the real part of T and Yout(:,2) is the imaginary part of T. nonlinear least square fitting transfer function MATLAB Answers — New Questions
Title is missing when saving a figure using print, saveas, exportgraphics, and printpreview
Context: When plotting images, I have often set the tick marks to face outward, where they are not obscured by the image. This change requires that I nudge the title upward by a small amount so that it is separated from the ticks.
Problem: When I save the file using print, saveas, exportgraphics or printpreview, the title is sometimes missing in the output file. (See attached examples above.)
I found that this problem occurs when the image is plotted using pcolor (and probably surf as well). It does not occur when using plot and imagesc. Annotation is used below to draw an outline of the outer extent of the figure. The nudged title clearly lies within that limit.
Work Around: The problem is fixed by ensuring that the Units property for the title is set to data after adjusting the title position. Note that I have filed a bug report with Matlab.
Versions: This problem did not occur with Matlab versions 2022a and earlier. It started with version 2022b and continues with version 2023a.
Coded example:
function test_figureTitleProblem
%… Simple demonstration of missing title problem.
% When plotting images, I have often set the tick marks to face outward,
% where they are not obscurved by the image. This change requires that
% I nudge the title upward by a small amount so that it is separated
% from the ticks.
%
% Problem: When I save the file using print, saveas, exportgraphics
% and printpreview, the title is missing in the output file.
% I found that this problem occurs when the image is plotted using
% pcolor, and does not occur when imagesc is used. I also found
% that the problem can be fixed by changing the Units property for the title
% back to data (see below). Annotation is used below to draw an outline of
% the outer extent of the figure. The nudged title clearly lies within
% that limit.
%% Initialize variables
%… Load Matlab’s global topographic data
load(‘topo.mat’, ‘topo’);
%… Create grid vectors
lon = 0:359;
lat = -89:90;
%% Plot
figure
%… Missing title occurs with pcolor, and not with imagesc
pcolor(lon, lat, topo)
shading interp
% imagesc(lon, lat, topo)
% axis xy
%… Format plot
hA = gca;
hA.Box = ‘on’;
hA.TickDir = ‘out’; % Oriented tick marks to face outward
hA.Layer = ‘top’; % Places grid lines and tick markers on top of image
hA.FontSize = 16;
hA.LineWidth = 1;
%… Render title, and nudge upward to separate from outward tick marks
hT = title(‘Demonstration of Demonstration of Missing Title’, ‘FontSize’, 16);
hT.Units = ‘normalized’;
hT.Position(2) = hT.Position(2) + 0.02;
% hT.Units = ‘data’; % Uncomment this line to fix problem
%… Draw rectangle to show outer limit for figure
annotation("rectangle", hA.OuterPosition, Color="red", LineWidth=1)
%… Start print preview to show that the title is missing
print(‘missingTitle_print.pdf’, ‘-dpdf’)
saveas(hA, ‘missingTitle_saveas.pdf’)
exportgraphics(hA, ‘missingTitle_exportgraphics.pdf’)
printpreview
endContext: When plotting images, I have often set the tick marks to face outward, where they are not obscured by the image. This change requires that I nudge the title upward by a small amount so that it is separated from the ticks.
Problem: When I save the file using print, saveas, exportgraphics or printpreview, the title is sometimes missing in the output file. (See attached examples above.)
I found that this problem occurs when the image is plotted using pcolor (and probably surf as well). It does not occur when using plot and imagesc. Annotation is used below to draw an outline of the outer extent of the figure. The nudged title clearly lies within that limit.
Work Around: The problem is fixed by ensuring that the Units property for the title is set to data after adjusting the title position. Note that I have filed a bug report with Matlab.
Versions: This problem did not occur with Matlab versions 2022a and earlier. It started with version 2022b and continues with version 2023a.
Coded example:
function test_figureTitleProblem
%… Simple demonstration of missing title problem.
% When plotting images, I have often set the tick marks to face outward,
% where they are not obscurved by the image. This change requires that
% I nudge the title upward by a small amount so that it is separated
% from the ticks.
%
% Problem: When I save the file using print, saveas, exportgraphics
% and printpreview, the title is missing in the output file.
% I found that this problem occurs when the image is plotted using
% pcolor, and does not occur when imagesc is used. I also found
% that the problem can be fixed by changing the Units property for the title
% back to data (see below). Annotation is used below to draw an outline of
% the outer extent of the figure. The nudged title clearly lies within
% that limit.
%% Initialize variables
%… Load Matlab’s global topographic data
load(‘topo.mat’, ‘topo’);
%… Create grid vectors
lon = 0:359;
lat = -89:90;
%% Plot
figure
%… Missing title occurs with pcolor, and not with imagesc
pcolor(lon, lat, topo)
shading interp
% imagesc(lon, lat, topo)
% axis xy
%… Format plot
hA = gca;
hA.Box = ‘on’;
hA.TickDir = ‘out’; % Oriented tick marks to face outward
hA.Layer = ‘top’; % Places grid lines and tick markers on top of image
hA.FontSize = 16;
hA.LineWidth = 1;
%… Render title, and nudge upward to separate from outward tick marks
hT = title(‘Demonstration of Demonstration of Missing Title’, ‘FontSize’, 16);
hT.Units = ‘normalized’;
hT.Position(2) = hT.Position(2) + 0.02;
% hT.Units = ‘data’; % Uncomment this line to fix problem
%… Draw rectangle to show outer limit for figure
annotation("rectangle", hA.OuterPosition, Color="red", LineWidth=1)
%… Start print preview to show that the title is missing
print(‘missingTitle_print.pdf’, ‘-dpdf’)
saveas(hA, ‘missingTitle_saveas.pdf’)
exportgraphics(hA, ‘missingTitle_exportgraphics.pdf’)
printpreview
end Context: When plotting images, I have often set the tick marks to face outward, where they are not obscured by the image. This change requires that I nudge the title upward by a small amount so that it is separated from the ticks.
Problem: When I save the file using print, saveas, exportgraphics or printpreview, the title is sometimes missing in the output file. (See attached examples above.)
I found that this problem occurs when the image is plotted using pcolor (and probably surf as well). It does not occur when using plot and imagesc. Annotation is used below to draw an outline of the outer extent of the figure. The nudged title clearly lies within that limit.
Work Around: The problem is fixed by ensuring that the Units property for the title is set to data after adjusting the title position. Note that I have filed a bug report with Matlab.
Versions: This problem did not occur with Matlab versions 2022a and earlier. It started with version 2022b and continues with version 2023a.
Coded example:
function test_figureTitleProblem
%… Simple demonstration of missing title problem.
% When plotting images, I have often set the tick marks to face outward,
% where they are not obscurved by the image. This change requires that
% I nudge the title upward by a small amount so that it is separated
% from the ticks.
%
% Problem: When I save the file using print, saveas, exportgraphics
% and printpreview, the title is missing in the output file.
% I found that this problem occurs when the image is plotted using
% pcolor, and does not occur when imagesc is used. I also found
% that the problem can be fixed by changing the Units property for the title
% back to data (see below). Annotation is used below to draw an outline of
% the outer extent of the figure. The nudged title clearly lies within
% that limit.
%% Initialize variables
%… Load Matlab’s global topographic data
load(‘topo.mat’, ‘topo’);
%… Create grid vectors
lon = 0:359;
lat = -89:90;
%% Plot
figure
%… Missing title occurs with pcolor, and not with imagesc
pcolor(lon, lat, topo)
shading interp
% imagesc(lon, lat, topo)
% axis xy
%… Format plot
hA = gca;
hA.Box = ‘on’;
hA.TickDir = ‘out’; % Oriented tick marks to face outward
hA.Layer = ‘top’; % Places grid lines and tick markers on top of image
hA.FontSize = 16;
hA.LineWidth = 1;
%… Render title, and nudge upward to separate from outward tick marks
hT = title(‘Demonstration of Demonstration of Missing Title’, ‘FontSize’, 16);
hT.Units = ‘normalized’;
hT.Position(2) = hT.Position(2) + 0.02;
% hT.Units = ‘data’; % Uncomment this line to fix problem
%… Draw rectangle to show outer limit for figure
annotation("rectangle", hA.OuterPosition, Color="red", LineWidth=1)
%… Start print preview to show that the title is missing
print(‘missingTitle_print.pdf’, ‘-dpdf’)
saveas(hA, ‘missingTitle_saveas.pdf’)
exportgraphics(hA, ‘missingTitle_exportgraphics.pdf’)
printpreview
end missing title MATLAB Answers — New Questions
proper IFFT procedure for converting S-params into time domain reflectometry
Basic discontinuety was simulated 0Hz to 40Ghz 40000 samples as presented in the photos . S-parameters were extracted as S2P file(attached in the link). My goal is to see the discontinuety using time domain reflectometry. what is the proper way to do IFFT in this case? What windows should I multiply with? Thanks.Basic discontinuety was simulated 0Hz to 40Ghz 40000 samples as presented in the photos . S-parameters were extracted as S2P file(attached in the link). My goal is to see the discontinuety using time domain reflectometry. what is the proper way to do IFFT in this case? What windows should I multiply with? Thanks. Basic discontinuety was simulated 0Hz to 40Ghz 40000 samples as presented in the photos . S-parameters were extracted as S2P file(attached in the link). My goal is to see the discontinuety using time domain reflectometry. what is the proper way to do IFFT in this case? What windows should I multiply with? Thanks. ifft, tdr, s-parameters MATLAB Answers — New Questions
Why Does polyval Return Zero When the Coefficients are Empty?
polyval([],1)
polyval(ones(1,0),1)
Do those results follow from a mathematical justification or are they arbitrarily specified?polyval([],1)
polyval(ones(1,0),1)
Do those results follow from a mathematical justification or are they arbitrarily specified? polyval([],1)
polyval(ones(1,0),1)
Do those results follow from a mathematical justification or are they arbitrarily specified? polynomial, empty coefficients MATLAB Answers — New Questions
I want to decrease the time my Script
Elapsed time is 8.597842 seconds.
clear, clc
tic
load(‘Erros_a.mat’); load(‘Sp1_b.mat’);
Relatorio = zeros(5000,4,’uint32′);
Relatorio_final = zeros(10000,4,’uint32′);
a = 10;
for i1 = 1:1
% BLOCO 1 — usa cache se existir, senão gera e salva
cache_file = sprintf(‘Erros_b_cache_%d.mat’, i1);
if exist(cache_file, ‘file’)
load(cache_file);
else
linha_a = Erros_a(a,:);
vals = linha_a(linha_a > 0);
vals = vals(1:end-2);
nRef = numel(vals);
cols_b1 = 2*(double(vals)-1) + 1;
cols_b2 = 2*(double(vals)-1) + 2;
passa = (Sp1_b(:, cols_b1) == 0) & (Sp1_b(:, cols_b2) == 0);
col_dest_matrix = uint32(cumsum(passa, 2) – passa + 1);
Erros_b = zeros(3268760, 37, ‘uint32’);
for d = 1:nRef
linhas_ok = find(passa(:, d));
if ~isempty(linhas_ok)
idx = sub2ind([3268760, 37], linhas_ok, double(col_dest_matrix(linhas_ok, d)));
Erros_b(idx) = vals(d);
end
end
save(cache_file, ‘Erros_b’, ‘-v7.3’);
end
% BLOCO 2 — preparação
load(‘Sp1_c.mat’);
Erros_b(:,38) = (1:size(Erros_b,1))’;
mascara = Erros_b(:, 13) > 50;
Erros_reduzido = Erros_b(mascara, :);
[lin_u, col_u] = find(Sp1_c == 1);
uns_nas_colunas = accumarray(col_u, lin_u, [size(Sp1_c,2) 1], @(x){sort(x)}, {[]});
clear Erros_b Sp1_c lin_u col_u mascara;
[~, ordem] = sortrows(Erros_reduzido(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido(ordem, :);
[~, ordem] = sortrows(Erros_reduzido_ordem(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido_ordem(ordem, :);
clear Erros_reduzido ordem;
ERO = double(Erros_reduzido_ordem);
clear Erros_reduzido_ordem;
nCols_c = numel(uns_nas_colunas);
uns_sets = cell(nCols_c, 1);
for cc = 1:nCols_c
s = uns_nas_colunas{cc};
if ~isempty(s)
m = false(max(s), 1);
m(s) = true;
uns_sets{cc} = m;
else
uns_sets{cc} = false(0,1);
end
end
% BLOCO 3 — while principal
num_linhas = size(ERO, 1);
y = 1;
offset = 0;
while (offset + 1) <= num_linhas
i = offset + 1;
linha_at = ERO(i, 1:38);
a_valid = linha_at(linha_at > 0 & linha_at <= 100);
% k=2: dois ponteiros
A = uns_nas_colunas{a_valid(1)};
B = uns_nas_colunas{a_valid(2)};
buf = zeros(min(numel(A), numel(B)), 1);
ia = 1; ib = 1; ic = 0;
na = numel(A); nb = numel(B);
while ia <= na && ib <= nb
if A(ia) == B(ib)
ic = ic + 1; buf(ic) = A(ia);
ia = ia + 1; ib = ib + 1;
elseif A(ia) < B(ib); ia = ia + 1;
else; ib = ib + 1;
end
end
candidatas = buf(1:ic);
w=1; z=1;
n(w,1) = a_valid(w,1);
achou = false;
if isempty(candidatas)
melhor_erro = a_valid(2) – 1;
melhor_linha = linha_at(38);
n(w,2) = a_valid(w,2);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = A(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
end
% k>=3: lookup lógico
for k = 3:length(a_valid)
if achou; break; end
n(w,k-1) = a_valid(w,k-1);
col_atual = a_valid(k);
s2 = uns_sets{col_atual};
if isempty(candidatas) || isempty(s2)
proximas = [];
else
mask = candidatas <= numel(s2);
cand_validas = candidatas(mask);
if isempty(cand_validas); proximas = [];
else; proximas = cand_validas(s2(cand_validas)); end
end
if isempty(proximas)
melhor_erro = col_atual – 1;
melhor_linha = linha_at(38);
n(w,k) = a_valid(w,k);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = candidatas(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
break;
end
candidatas = proximas;
melhor_linha = candidatas(1);
end % for k
if ~achou; offset = offset + 1; end
end % while
clear ERO uns_sets;
Relatorio = sortrows(Relatorio, 4, ‘descend’);
Relatorio_final(i1,:) = Relatorio(1,:);
Relatorio(:,:) = 0;
a = a + 1;
end % i1
tocElapsed time is 8.597842 seconds.
clear, clc
tic
load(‘Erros_a.mat’); load(‘Sp1_b.mat’);
Relatorio = zeros(5000,4,’uint32′);
Relatorio_final = zeros(10000,4,’uint32′);
a = 10;
for i1 = 1:1
% BLOCO 1 — usa cache se existir, senão gera e salva
cache_file = sprintf(‘Erros_b_cache_%d.mat’, i1);
if exist(cache_file, ‘file’)
load(cache_file);
else
linha_a = Erros_a(a,:);
vals = linha_a(linha_a > 0);
vals = vals(1:end-2);
nRef = numel(vals);
cols_b1 = 2*(double(vals)-1) + 1;
cols_b2 = 2*(double(vals)-1) + 2;
passa = (Sp1_b(:, cols_b1) == 0) & (Sp1_b(:, cols_b2) == 0);
col_dest_matrix = uint32(cumsum(passa, 2) – passa + 1);
Erros_b = zeros(3268760, 37, ‘uint32’);
for d = 1:nRef
linhas_ok = find(passa(:, d));
if ~isempty(linhas_ok)
idx = sub2ind([3268760, 37], linhas_ok, double(col_dest_matrix(linhas_ok, d)));
Erros_b(idx) = vals(d);
end
end
save(cache_file, ‘Erros_b’, ‘-v7.3’);
end
% BLOCO 2 — preparação
load(‘Sp1_c.mat’);
Erros_b(:,38) = (1:size(Erros_b,1))’;
mascara = Erros_b(:, 13) > 50;
Erros_reduzido = Erros_b(mascara, :);
[lin_u, col_u] = find(Sp1_c == 1);
uns_nas_colunas = accumarray(col_u, lin_u, [size(Sp1_c,2) 1], @(x){sort(x)}, {[]});
clear Erros_b Sp1_c lin_u col_u mascara;
[~, ordem] = sortrows(Erros_reduzido(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido(ordem, :);
[~, ordem] = sortrows(Erros_reduzido_ordem(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido_ordem(ordem, :);
clear Erros_reduzido ordem;
ERO = double(Erros_reduzido_ordem);
clear Erros_reduzido_ordem;
nCols_c = numel(uns_nas_colunas);
uns_sets = cell(nCols_c, 1);
for cc = 1:nCols_c
s = uns_nas_colunas{cc};
if ~isempty(s)
m = false(max(s), 1);
m(s) = true;
uns_sets{cc} = m;
else
uns_sets{cc} = false(0,1);
end
end
% BLOCO 3 — while principal
num_linhas = size(ERO, 1);
y = 1;
offset = 0;
while (offset + 1) <= num_linhas
i = offset + 1;
linha_at = ERO(i, 1:38);
a_valid = linha_at(linha_at > 0 & linha_at <= 100);
% k=2: dois ponteiros
A = uns_nas_colunas{a_valid(1)};
B = uns_nas_colunas{a_valid(2)};
buf = zeros(min(numel(A), numel(B)), 1);
ia = 1; ib = 1; ic = 0;
na = numel(A); nb = numel(B);
while ia <= na && ib <= nb
if A(ia) == B(ib)
ic = ic + 1; buf(ic) = A(ia);
ia = ia + 1; ib = ib + 1;
elseif A(ia) < B(ib); ia = ia + 1;
else; ib = ib + 1;
end
end
candidatas = buf(1:ic);
w=1; z=1;
n(w,1) = a_valid(w,1);
achou = false;
if isempty(candidatas)
melhor_erro = a_valid(2) – 1;
melhor_linha = linha_at(38);
n(w,2) = a_valid(w,2);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = A(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
end
% k>=3: lookup lógico
for k = 3:length(a_valid)
if achou; break; end
n(w,k-1) = a_valid(w,k-1);
col_atual = a_valid(k);
s2 = uns_sets{col_atual};
if isempty(candidatas) || isempty(s2)
proximas = [];
else
mask = candidatas <= numel(s2);
cand_validas = candidatas(mask);
if isempty(cand_validas); proximas = [];
else; proximas = cand_validas(s2(cand_validas)); end
end
if isempty(proximas)
melhor_erro = col_atual – 1;
melhor_linha = linha_at(38);
n(w,k) = a_valid(w,k);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = candidatas(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
break;
end
candidatas = proximas;
melhor_linha = candidatas(1);
end % for k
if ~achou; offset = offset + 1; end
end % while
clear ERO uns_sets;
Relatorio = sortrows(Relatorio, 4, ‘descend’);
Relatorio_final(i1,:) = Relatorio(1,:);
Relatorio(:,:) = 0;
a = a + 1;
end % i1
toc Elapsed time is 8.597842 seconds.
clear, clc
tic
load(‘Erros_a.mat’); load(‘Sp1_b.mat’);
Relatorio = zeros(5000,4,’uint32′);
Relatorio_final = zeros(10000,4,’uint32′);
a = 10;
for i1 = 1:1
% BLOCO 1 — usa cache se existir, senão gera e salva
cache_file = sprintf(‘Erros_b_cache_%d.mat’, i1);
if exist(cache_file, ‘file’)
load(cache_file);
else
linha_a = Erros_a(a,:);
vals = linha_a(linha_a > 0);
vals = vals(1:end-2);
nRef = numel(vals);
cols_b1 = 2*(double(vals)-1) + 1;
cols_b2 = 2*(double(vals)-1) + 2;
passa = (Sp1_b(:, cols_b1) == 0) & (Sp1_b(:, cols_b2) == 0);
col_dest_matrix = uint32(cumsum(passa, 2) – passa + 1);
Erros_b = zeros(3268760, 37, ‘uint32’);
for d = 1:nRef
linhas_ok = find(passa(:, d));
if ~isempty(linhas_ok)
idx = sub2ind([3268760, 37], linhas_ok, double(col_dest_matrix(linhas_ok, d)));
Erros_b(idx) = vals(d);
end
end
save(cache_file, ‘Erros_b’, ‘-v7.3’);
end
% BLOCO 2 — preparação
load(‘Sp1_c.mat’);
Erros_b(:,38) = (1:size(Erros_b,1))’;
mascara = Erros_b(:, 13) > 50;
Erros_reduzido = Erros_b(mascara, :);
[lin_u, col_u] = find(Sp1_c == 1);
uns_nas_colunas = accumarray(col_u, lin_u, [size(Sp1_c,2) 1], @(x){sort(x)}, {[]});
clear Erros_b Sp1_c lin_u col_u mascara;
[~, ordem] = sortrows(Erros_reduzido(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido(ordem, :);
[~, ordem] = sortrows(Erros_reduzido_ordem(:, 1:38));
Erros_reduzido_ordem = Erros_reduzido_ordem(ordem, :);
clear Erros_reduzido ordem;
ERO = double(Erros_reduzido_ordem);
clear Erros_reduzido_ordem;
nCols_c = numel(uns_nas_colunas);
uns_sets = cell(nCols_c, 1);
for cc = 1:nCols_c
s = uns_nas_colunas{cc};
if ~isempty(s)
m = false(max(s), 1);
m(s) = true;
uns_sets{cc} = m;
else
uns_sets{cc} = false(0,1);
end
end
% BLOCO 3 — while principal
num_linhas = size(ERO, 1);
y = 1;
offset = 0;
while (offset + 1) <= num_linhas
i = offset + 1;
linha_at = ERO(i, 1:38);
a_valid = linha_at(linha_at > 0 & linha_at <= 100);
% k=2: dois ponteiros
A = uns_nas_colunas{a_valid(1)};
B = uns_nas_colunas{a_valid(2)};
buf = zeros(min(numel(A), numel(B)), 1);
ia = 1; ib = 1; ic = 0;
na = numel(A); nb = numel(B);
while ia <= na && ib <= nb
if A(ia) == B(ib)
ic = ic + 1; buf(ic) = A(ia);
ia = ia + 1; ib = ib + 1;
elseif A(ia) < B(ib); ia = ia + 1;
else; ib = ib + 1;
end
end
candidatas = buf(1:ic);
w=1; z=1;
n(w,1) = a_valid(w,1);
achou = false;
if isempty(candidatas)
melhor_erro = a_valid(2) – 1;
melhor_linha = linha_at(38);
n(w,2) = a_valid(w,2);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = A(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
end
% k>=3: lookup lógico
for k = 3:length(a_valid)
if achou; break; end
n(w,k-1) = a_valid(w,k-1);
col_atual = a_valid(k);
s2 = uns_sets{col_atual};
if isempty(candidatas) || isempty(s2)
proximas = [];
else
mask = candidatas <= numel(s2);
cand_validas = candidatas(mask);
if isempty(cand_validas); proximas = [];
else; proximas = cand_validas(s2(cand_validas)); end
end
if isempty(proximas)
melhor_erro = col_atual – 1;
melhor_linha = linha_at(38);
n(w,k) = a_valid(w,k);
nP = length(n);
lo = offset + 1; hi = num_linhas; ultlin_abs = offset;
if all(ERO(lo, 1:nP) == n)
while lo <= hi
mid = floor((lo + hi) / 2);
if all(ERO(mid, 1:nP) == n)
ultlin_abs = mid; lo = mid + 1;
else; hi = mid – 1; end
end
end
if ultlin_abs > offset; offset = ultlin_abs;
else; offset = offset + 1; end
n = [];
Relatorio(y,1) = Erros_a(i1,40);
Relatorio(y,2) = candidatas(1);
Relatorio(y,3) = melhor_linha;
Relatorio(y,4) = melhor_erro;
y = y + 1;
achou = true;
break;
end
candidatas = proximas;
melhor_linha = candidatas(1);
end % for k
if ~achou; offset = offset + 1; end
end % while
clear ERO uns_sets;
Relatorio = sortrows(Relatorio, 4, ‘descend’);
Relatorio_final(i1,:) = Relatorio(1,:);
Relatorio(:,:) = 0;
a = a + 1;
end % i1
toc script slow MATLAB Answers — New Questions
Multithreding causing system crashes on linux
Hello,
Im trying to run a rather heavy calculation on our server, and high levels of multithreading causes the system to crash, sadly without crash log. The system does not respond to anything, both over the network and pressing the power button, and requires the power connection to be pulled before it can restart.
The linux version is "Ubunto 24.04.2 LTS", with two AMD EPYC 7763 64-Core Processor CPUs, about 1 TB of ram, a GeForce RTX 3050 8GB graphics card and a Supermicro H12DSi-NT6 mainboard.
When I use parpool and maxNumCompThreads at 16, the system works fine, but rather slow. At 32, the system works fine for a couple of minutes, before crashing, even when the CPU and Ram load never goes above 20%.
The computations include ffts, interpolation and complex to real and vice versa conversions.
Do you have any tips or hints where I can check what is happening, or do you have any information what is going on and what I can do to resolve this problem?
ThanksHello,
Im trying to run a rather heavy calculation on our server, and high levels of multithreading causes the system to crash, sadly without crash log. The system does not respond to anything, both over the network and pressing the power button, and requires the power connection to be pulled before it can restart.
The linux version is "Ubunto 24.04.2 LTS", with two AMD EPYC 7763 64-Core Processor CPUs, about 1 TB of ram, a GeForce RTX 3050 8GB graphics card and a Supermicro H12DSi-NT6 mainboard.
When I use parpool and maxNumCompThreads at 16, the system works fine, but rather slow. At 32, the system works fine for a couple of minutes, before crashing, even when the CPU and Ram load never goes above 20%.
The computations include ffts, interpolation and complex to real and vice versa conversions.
Do you have any tips or hints where I can check what is happening, or do you have any information what is going on and what I can do to resolve this problem?
Thanks Hello,
Im trying to run a rather heavy calculation on our server, and high levels of multithreading causes the system to crash, sadly without crash log. The system does not respond to anything, both over the network and pressing the power button, and requires the power connection to be pulled before it can restart.
The linux version is "Ubunto 24.04.2 LTS", with two AMD EPYC 7763 64-Core Processor CPUs, about 1 TB of ram, a GeForce RTX 3050 8GB graphics card and a Supermicro H12DSi-NT6 mainboard.
When I use parpool and maxNumCompThreads at 16, the system works fine, but rather slow. At 32, the system works fine for a couple of minutes, before crashing, even when the CPU and Ram load never goes above 20%.
The computations include ffts, interpolation and complex to real and vice versa conversions.
Do you have any tips or hints where I can check what is happening, or do you have any information what is going on and what I can do to resolve this problem?
Thanks parfor, multithreading, error, performance MATLAB Answers — New Questions
How to sign an .mlapp app packaged using MATLAB App designer?
Using Share to "Standalone Desktop App" in MATLAB App Designer, Is there a way to sign the installer .exe file that is generated, and also sign the application .exe file that is generated after the installation file is run? Currently, when using App Designer to package the app, it creates a build of the app and then packages it into an installation .exe file in the same workflow.
The issue I’m forseeing is that if I sign the installation .exe file, the application .exe file within will still be un-signed when it is generated after the installer is run. Am I right in thinking this? If so, is there a method of ensuring the application .exe file within is signed?Using Share to "Standalone Desktop App" in MATLAB App Designer, Is there a way to sign the installer .exe file that is generated, and also sign the application .exe file that is generated after the installation file is run? Currently, when using App Designer to package the app, it creates a build of the app and then packages it into an installation .exe file in the same workflow.
The issue I’m forseeing is that if I sign the installation .exe file, the application .exe file within will still be un-signed when it is generated after the installer is run. Am I right in thinking this? If so, is there a method of ensuring the application .exe file within is signed? Using Share to "Standalone Desktop App" in MATLAB App Designer, Is there a way to sign the installer .exe file that is generated, and also sign the application .exe file that is generated after the installation file is run? Currently, when using App Designer to package the app, it creates a build of the app and then packages it into an installation .exe file in the same workflow.
The issue I’m forseeing is that if I sign the installation .exe file, the application .exe file within will still be un-signed when it is generated after the installer is run. Am I right in thinking this? If so, is there a method of ensuring the application .exe file within is signed? app designer, compiler, certificate, signing MATLAB Answers — New Questions
“operation not allowed” when accessing network drive
I get an "operation not allowed" error in Matlab (only in Matlab) on MacOS when trying to access network-mounted RAID drive
Desktop Mac (1) running Macos 26.3.1, has network-mounted a USB-C external RAID drive connected to older desktop Mac (2) running 15.7.4.
I can view, edit, save etc. files on the (remote) RAID system using terminal windows on (1), using Finder, TextEdit, etc.. But attempting to access folders or files from within Matlab R2024b returns the error "operation not allowed".
Both systems (1) & (2) have Matlab given "full disk access" in Settings>Privacy&Security>FullDiskAccess. Both systems have user given read&write access for shared network drive in Finder>Get_Info, in Unix permissions, and in Settings>Sharing>File_Sharing.
Matlab on (2) can read & write files on the (locally-attached) RAID drive. The problem is only when trying to access the RAID drive from within in Matlab on (1).
smbd also has full disk access (as is clear since terminal and other apps can read & write RAID drive over network connection).
Any suggestions would be appreciated.I get an "operation not allowed" error in Matlab (only in Matlab) on MacOS when trying to access network-mounted RAID drive
Desktop Mac (1) running Macos 26.3.1, has network-mounted a USB-C external RAID drive connected to older desktop Mac (2) running 15.7.4.
I can view, edit, save etc. files on the (remote) RAID system using terminal windows on (1), using Finder, TextEdit, etc.. But attempting to access folders or files from within Matlab R2024b returns the error "operation not allowed".
Both systems (1) & (2) have Matlab given "full disk access" in Settings>Privacy&Security>FullDiskAccess. Both systems have user given read&write access for shared network drive in Finder>Get_Info, in Unix permissions, and in Settings>Sharing>File_Sharing.
Matlab on (2) can read & write files on the (locally-attached) RAID drive. The problem is only when trying to access the RAID drive from within in Matlab on (1).
smbd also has full disk access (as is clear since terminal and other apps can read & write RAID drive over network connection).
Any suggestions would be appreciated. I get an "operation not allowed" error in Matlab (only in Matlab) on MacOS when trying to access network-mounted RAID drive
Desktop Mac (1) running Macos 26.3.1, has network-mounted a USB-C external RAID drive connected to older desktop Mac (2) running 15.7.4.
I can view, edit, save etc. files on the (remote) RAID system using terminal windows on (1), using Finder, TextEdit, etc.. But attempting to access folders or files from within Matlab R2024b returns the error "operation not allowed".
Both systems (1) & (2) have Matlab given "full disk access" in Settings>Privacy&Security>FullDiskAccess. Both systems have user given read&write access for shared network drive in Finder>Get_Info, in Unix permissions, and in Settings>Sharing>File_Sharing.
Matlab on (2) can read & write files on the (locally-attached) RAID drive. The problem is only when trying to access the RAID drive from within in Matlab on (1).
smbd also has full disk access (as is clear since terminal and other apps can read & write RAID drive over network connection).
Any suggestions would be appreciated. operation not allowed MATLAB Answers — New Questions
How do I determine the linear part of a force-displacement curve?
I have a force-displacement graph (the attached file) and I want to find out exactly at what point the linear portion of the graph ends. Please see the picture for more clarification.
I’ve already smoothed out the curve, so it is noiseless.
I did a quick search but couldn’t find anything useful.
Any help would be highly appreciated.I have a force-displacement graph (the attached file) and I want to find out exactly at what point the linear portion of the graph ends. Please see the picture for more clarification.
I’ve already smoothed out the curve, so it is noiseless.
I did a quick search but couldn’t find anything useful.
Any help would be highly appreciated. I have a force-displacement graph (the attached file) and I want to find out exactly at what point the linear portion of the graph ends. Please see the picture for more clarification.
I’ve already smoothed out the curve, so it is noiseless.
I did a quick search but couldn’t find anything useful.
Any help would be highly appreciated. linear part, nonlinear part MATLAB Answers — New Questions
Best way to relabel axis as pi for trig functions.
Hi all, I was looking for ways to relabel my x-axis as pi increments for trig functions and was wondering which one would be most effective.
This is what chatgpt gave, but I wanted to see if there are any better ways to achieve the same result. TIA!!
clc, clearvars
x = linspace(0,2*pi,200);
y = sin(x);
% Plot
figure
hold on
plot(x, y)
% Pi Labeling
xt = 0:pi/2:2*pi;
xticks(xt)
label = compose(‘%g\pi’, xt/pi);
xticklabels(label)Hi all, I was looking for ways to relabel my x-axis as pi increments for trig functions and was wondering which one would be most effective.
This is what chatgpt gave, but I wanted to see if there are any better ways to achieve the same result. TIA!!
clc, clearvars
x = linspace(0,2*pi,200);
y = sin(x);
% Plot
figure
hold on
plot(x, y)
% Pi Labeling
xt = 0:pi/2:2*pi;
xticks(xt)
label = compose(‘%g\pi’, xt/pi);
xticklabels(label) Hi all, I was looking for ways to relabel my x-axis as pi increments for trig functions and was wondering which one would be most effective.
This is what chatgpt gave, but I wanted to see if there are any better ways to achieve the same result. TIA!!
clc, clearvars
x = linspace(0,2*pi,200);
y = sin(x);
% Plot
figure
hold on
plot(x, y)
% Pi Labeling
xt = 0:pi/2:2*pi;
xticks(xt)
label = compose(‘%g\pi’, xt/pi);
xticklabels(label) xtick, label, trigonometry, pi MATLAB Answers — New Questions
Probléme sur mon programme matlab avec la fonction lsqcurvefit
Bonjour la communauté,
enfaite présentatement je travail sur un programme qui permets de recueillir les paramétre du modèle de Cole_cole à partir des mesures que j’ai eu. Donc l’idéé c’est de faire un programme qui va tracer une courbe qui se superpose à la mesure et me donner les paramétre du modèle correspondant. là j’utilise le lsqcurvefit mais le programme me retourne les valeurs d’initialisation et je sais pas ca peut être dû quoi ?
Merci d’avance de votre réponseBonjour la communauté,
enfaite présentatement je travail sur un programme qui permets de recueillir les paramétre du modèle de Cole_cole à partir des mesures que j’ai eu. Donc l’idéé c’est de faire un programme qui va tracer une courbe qui se superpose à la mesure et me donner les paramétre du modèle correspondant. là j’utilise le lsqcurvefit mais le programme me retourne les valeurs d’initialisation et je sais pas ca peut être dû quoi ?
Merci d’avance de votre réponse Bonjour la communauté,
enfaite présentatement je travail sur un programme qui permets de recueillir les paramétre du modèle de Cole_cole à partir des mesures que j’ai eu. Donc l’idéé c’est de faire un programme qui va tracer une courbe qui se superpose à la mesure et me donner les paramétre du modèle correspondant. là j’utilise le lsqcurvefit mais le programme me retourne les valeurs d’initialisation et je sais pas ca peut être dû quoi ?
Merci d’avance de votre réponse mbengue MATLAB Answers — New Questions
“Index exceeds 37” when 35 variables?
So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject)So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject) So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject) error, curve fitting MATLAB Answers — New Questions
How to use AI to edit UI of app using AppDesigner
We are building an app with AppDesigner (24b currently). To get help designing we are using AI features. The suggestions seem good, and I want to adapt my AppDesigner Code. However, the code of the UI is greyed out. Secondly, unzipping the .mlapp and editing the matlab/document.xml does not work, as zipping again creates an not running (and smaller in size) .mlapp file. Is there a way to get access to the UI Code and to edit it effectively? Thank you.We are building an app with AppDesigner (24b currently). To get help designing we are using AI features. The suggestions seem good, and I want to adapt my AppDesigner Code. However, the code of the UI is greyed out. Secondly, unzipping the .mlapp and editing the matlab/document.xml does not work, as zipping again creates an not running (and smaller in size) .mlapp file. Is there a way to get access to the UI Code and to edit it effectively? Thank you. We are building an app with AppDesigner (24b currently). To get help designing we are using AI features. The suggestions seem good, and I want to adapt my AppDesigner Code. However, the code of the UI is greyed out. Secondly, unzipping the .mlapp and editing the matlab/document.xml does not work, as zipping again creates an not running (and smaller in size) .mlapp file. Is there a way to get access to the UI Code and to edit it effectively? Thank you. appdesigner, ai MATLAB Answers — New Questions
Why is Jaaba stuck open on MATLAB online?
I was trying to run JAABA and realized I don’t have the correct video file format yet, but when I tried to exit out of the dialog box that comes up it is completely frozen. I can’t type or select anything in matlab online and even when I close out of it and reopen the dialog box is still stuck there. Thank you!I was trying to run JAABA and realized I don’t have the correct video file format yet, but when I tried to exit out of the dialog box that comes up it is completely frozen. I can’t type or select anything in matlab online and even when I close out of it and reopen the dialog box is still stuck there. Thank you! I was trying to run JAABA and realized I don’t have the correct video file format yet, but when I tried to exit out of the dialog box that comes up it is completely frozen. I can’t type or select anything in matlab online and even when I close out of it and reopen the dialog box is still stuck there. Thank you! jaaba, frozen, stuck MATLAB Answers — New Questions
How do I install additional toolboxes into an existing installation of MATLAB?
New toolboxes have just been added to my license. How do I install additional toolboxes into an existing installation of MATLAB?New toolboxes have just been added to my license. How do I install additional toolboxes into an existing installation of MATLAB? New toolboxes have just been added to my license. How do I install additional toolboxes into an existing installation of MATLAB? MATLAB Answers — New Questions
Undefined function ‘imhistc’ for input arguments of type ‘uint8’.
Im trying to get the histogram of an image using imhist. however its showing the above error? i tried which imhistc and its not found. Im using matlab R2016Im trying to get the histogram of an image using imhist. however its showing the above error? i tried which imhistc and its not found. Im using matlab R2016 Im trying to get the histogram of an image using imhist. however its showing the above error? i tried which imhistc and its not found. Im using matlab R2016 matlab, histogram MATLAB Answers — New Questions
Kinks/discontinuities in pdepe solution
Hello everyone,
I’ve been working with Matlab pdepe to solve numerically a set of coupled partial differential equations. I’m fairly new and I’ve encountered a problem with the numerical solution that I get from my code and can’t seem to get rid of it. The equations model the diffusion and decay of two species in a material over 100s of ns. The problem I’m getting is that when I look at the solution in a log time scale, several kinks appear. Here are different things I’ve tried and haven’t helped:
Make tspan finer. (30-1000 points)
Make xmesh finer. (50-1000 points)
Increase or decrease relative tolerance (1E0 to 1E-6).
Make tspan time separation linear after t = 0.
Make tspan time separation increase logarithmically after t = 0.1 s
Any insights into how I could solve the problem would be useful.
% Physical constants
%params = [DR TR TT A B];
DR_guess = 1E6; % in nm^2 /ns
DT_guess = 1E1; % in nm^2 /ns
TR_guess = 14; % in ns
TT_guess = 130; % in ns
T0 = 295; % in K
R0 = 0.016;% in e/nm^3
A = 1;
B = 200;
Y = 0.3056;
CR = -80000;
CT = 220;
params = [DR_guess DT_guess TR_guess TT_guess T0 R0 A B Y CR CT];
% Setting up the mesh for space and time
xmesh = linspace(0,2000,55); %in nm
tspan = [-5, -2, -1, -0.5, 0, logspace(-1, 3, 80)];% in ns
% Solving the differential equation
options = odeset(‘RelTol’,1e-0,’OutputFcn’,@myOut,’Stats’,’on’);
pde = @(x, t, u, dudx) AgSepde(x, t, u, dudx, params);
soln = pdepe(1, pde, @AgSeic, @AgSebc, xmesh, tspan, options);
% Partial differential equation function
function [c,f,s] = AgSepde(x,t,u,dudx,params)
% Parameters for PDEs
DR = params(1);
DT = params(2);
TR = params(3);
TT = params(4);
T0 = params(5);
R0 = params(6);
A = params(7);
B = params(8);
Y = params(9);
% Generation function
sigmar = 180; % in nm
sigmat = 0.2; %in ns
t0 = 0.00; % in ns
G = (1 / (sigmar * sqrt(2*pi))) * exp(-x.^2 / (2 * sigmar^2)) …
* (1 / (sigmat * sqrt(2*pi))) * exp(-(t – t0).^2 / (2 * sigmat^2));
c = [1; 1];
f = [DR*dudx(1); DT*dudx(2)];
s = [-(u(1) – R0)/TR + A*G; Y*(u(1)- R0) – (u(2) – T0)/TT + B*G];
end
% Intial conditions for the PDEs
function u0 = AgSeic(x)
T0 = 295;
R0 = 0.016;
u0 = [R0; T0];
end
function [pl, ql, pr, qr] = AgSebc(xl, ul, xr, ur, t)
% Left boundary: u(0,t) = 1
pl = [0; 0];
ql = [1; 1];
% Right boundary: u(x’,t) = 0
pr = [0; 0];
qr = [1; 1];
end
function status = myOut(t,y,flag)
persistent last
if strcmp(flag,’init’), last = tic; end
if isempty(flag) && toc(last) > 1
fprintf(‘t = %.3g nsn’, t(end));
last = tic;
end
status = 0;
end
%% Figures
tiledlayout(2,1)
nexttile(1,[1,1])
hold on;
plot(tspan,soln(:,1,1),’Marker’,’o’);
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 1’);
hold off;
nexttile(2,[1,1])
hold on;
plot(tspan,soln(:,1,2),’Marker’,’square’)
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 2’);
hold off;Hello everyone,
I’ve been working with Matlab pdepe to solve numerically a set of coupled partial differential equations. I’m fairly new and I’ve encountered a problem with the numerical solution that I get from my code and can’t seem to get rid of it. The equations model the diffusion and decay of two species in a material over 100s of ns. The problem I’m getting is that when I look at the solution in a log time scale, several kinks appear. Here are different things I’ve tried and haven’t helped:
Make tspan finer. (30-1000 points)
Make xmesh finer. (50-1000 points)
Increase or decrease relative tolerance (1E0 to 1E-6).
Make tspan time separation linear after t = 0.
Make tspan time separation increase logarithmically after t = 0.1 s
Any insights into how I could solve the problem would be useful.
% Physical constants
%params = [DR TR TT A B];
DR_guess = 1E6; % in nm^2 /ns
DT_guess = 1E1; % in nm^2 /ns
TR_guess = 14; % in ns
TT_guess = 130; % in ns
T0 = 295; % in K
R0 = 0.016;% in e/nm^3
A = 1;
B = 200;
Y = 0.3056;
CR = -80000;
CT = 220;
params = [DR_guess DT_guess TR_guess TT_guess T0 R0 A B Y CR CT];
% Setting up the mesh for space and time
xmesh = linspace(0,2000,55); %in nm
tspan = [-5, -2, -1, -0.5, 0, logspace(-1, 3, 80)];% in ns
% Solving the differential equation
options = odeset(‘RelTol’,1e-0,’OutputFcn’,@myOut,’Stats’,’on’);
pde = @(x, t, u, dudx) AgSepde(x, t, u, dudx, params);
soln = pdepe(1, pde, @AgSeic, @AgSebc, xmesh, tspan, options);
% Partial differential equation function
function [c,f,s] = AgSepde(x,t,u,dudx,params)
% Parameters for PDEs
DR = params(1);
DT = params(2);
TR = params(3);
TT = params(4);
T0 = params(5);
R0 = params(6);
A = params(7);
B = params(8);
Y = params(9);
% Generation function
sigmar = 180; % in nm
sigmat = 0.2; %in ns
t0 = 0.00; % in ns
G = (1 / (sigmar * sqrt(2*pi))) * exp(-x.^2 / (2 * sigmar^2)) …
* (1 / (sigmat * sqrt(2*pi))) * exp(-(t – t0).^2 / (2 * sigmat^2));
c = [1; 1];
f = [DR*dudx(1); DT*dudx(2)];
s = [-(u(1) – R0)/TR + A*G; Y*(u(1)- R0) – (u(2) – T0)/TT + B*G];
end
% Intial conditions for the PDEs
function u0 = AgSeic(x)
T0 = 295;
R0 = 0.016;
u0 = [R0; T0];
end
function [pl, ql, pr, qr] = AgSebc(xl, ul, xr, ur, t)
% Left boundary: u(0,t) = 1
pl = [0; 0];
ql = [1; 1];
% Right boundary: u(x’,t) = 0
pr = [0; 0];
qr = [1; 1];
end
function status = myOut(t,y,flag)
persistent last
if strcmp(flag,’init’), last = tic; end
if isempty(flag) && toc(last) > 1
fprintf(‘t = %.3g nsn’, t(end));
last = tic;
end
status = 0;
end
%% Figures
tiledlayout(2,1)
nexttile(1,[1,1])
hold on;
plot(tspan,soln(:,1,1),’Marker’,’o’);
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 1’);
hold off;
nexttile(2,[1,1])
hold on;
plot(tspan,soln(:,1,2),’Marker’,’square’)
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 2’);
hold off; Hello everyone,
I’ve been working with Matlab pdepe to solve numerically a set of coupled partial differential equations. I’m fairly new and I’ve encountered a problem with the numerical solution that I get from my code and can’t seem to get rid of it. The equations model the diffusion and decay of two species in a material over 100s of ns. The problem I’m getting is that when I look at the solution in a log time scale, several kinks appear. Here are different things I’ve tried and haven’t helped:
Make tspan finer. (30-1000 points)
Make xmesh finer. (50-1000 points)
Increase or decrease relative tolerance (1E0 to 1E-6).
Make tspan time separation linear after t = 0.
Make tspan time separation increase logarithmically after t = 0.1 s
Any insights into how I could solve the problem would be useful.
% Physical constants
%params = [DR TR TT A B];
DR_guess = 1E6; % in nm^2 /ns
DT_guess = 1E1; % in nm^2 /ns
TR_guess = 14; % in ns
TT_guess = 130; % in ns
T0 = 295; % in K
R0 = 0.016;% in e/nm^3
A = 1;
B = 200;
Y = 0.3056;
CR = -80000;
CT = 220;
params = [DR_guess DT_guess TR_guess TT_guess T0 R0 A B Y CR CT];
% Setting up the mesh for space and time
xmesh = linspace(0,2000,55); %in nm
tspan = [-5, -2, -1, -0.5, 0, logspace(-1, 3, 80)];% in ns
% Solving the differential equation
options = odeset(‘RelTol’,1e-0,’OutputFcn’,@myOut,’Stats’,’on’);
pde = @(x, t, u, dudx) AgSepde(x, t, u, dudx, params);
soln = pdepe(1, pde, @AgSeic, @AgSebc, xmesh, tspan, options);
% Partial differential equation function
function [c,f,s] = AgSepde(x,t,u,dudx,params)
% Parameters for PDEs
DR = params(1);
DT = params(2);
TR = params(3);
TT = params(4);
T0 = params(5);
R0 = params(6);
A = params(7);
B = params(8);
Y = params(9);
% Generation function
sigmar = 180; % in nm
sigmat = 0.2; %in ns
t0 = 0.00; % in ns
G = (1 / (sigmar * sqrt(2*pi))) * exp(-x.^2 / (2 * sigmar^2)) …
* (1 / (sigmat * sqrt(2*pi))) * exp(-(t – t0).^2 / (2 * sigmat^2));
c = [1; 1];
f = [DR*dudx(1); DT*dudx(2)];
s = [-(u(1) – R0)/TR + A*G; Y*(u(1)- R0) – (u(2) – T0)/TT + B*G];
end
% Intial conditions for the PDEs
function u0 = AgSeic(x)
T0 = 295;
R0 = 0.016;
u0 = [R0; T0];
end
function [pl, ql, pr, qr] = AgSebc(xl, ul, xr, ur, t)
% Left boundary: u(0,t) = 1
pl = [0; 0];
ql = [1; 1];
% Right boundary: u(x’,t) = 0
pr = [0; 0];
qr = [1; 1];
end
function status = myOut(t,y,flag)
persistent last
if strcmp(flag,’init’), last = tic; end
if isempty(flag) && toc(last) > 1
fprintf(‘t = %.3g nsn’, t(end));
last = tic;
end
status = 0;
end
%% Figures
tiledlayout(2,1)
nexttile(1,[1,1])
hold on;
plot(tspan,soln(:,1,1),’Marker’,’o’);
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 1’);
hold off;
nexttile(2,[1,1])
hold on;
plot(tspan,soln(:,1,2),’Marker’,’square’)
set(gca,’XScale’,’log’);
xlabel(‘Time / ns’);
ylabel(‘Species 2’);
hold off; pde, pdepe MATLAB Answers — New Questions









