Month: May 2024
data not generating and error in plotting
% Define initial parameters
lambda_init = 2;
kappa_init = 1;
theta_k_init = pi/10;
R_init = 7;
rout = 3;
% Define c
c = sqrt(4 – (rout/R_init)^2);
% Define the function for the differential equations
f = @(r, y) [y(2); ((-1*(lambda_init+1)*(r*y(2)+y(1)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1))-(kappa_init*r*y(3)*sin(theta_k_init))+(-16*lambda_init*r^2)/(c^4*R_init^2)); y(4); ((-1*(r*y(4)+y(3)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-1)*y(3))+(kappa_init*r*y(1)*sin(theta_k_init)))];
% Solve the differential equations using ode45
r_span = linspace(0, rout, 100); % Define the range of r values
[~, sol] = ode45(f, r_span, [0, 0, 0, 0]);
% Extract solutions
dr_sol = sol(:,1);
dtheta_sol = sol(:,3);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r_span, dr_sol, ‘b-‘);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Solution of dr(r) vs r’);
subplot(2,1,2);
plot(r_span, dtheta_sol, ‘b-‘);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Solution of dtheta(r) vs r’);
I am trying to solve the coupled differential eqns for d_r(r) vs r and d_theta(r) vs r for these parameter values and boundary conditions so that it is zero at both end d_r(0) = d_r(rout) = 0 and the same for d_theta. However, Not able to see the plot and data. please suggest me errors.% Define initial parameters
lambda_init = 2;
kappa_init = 1;
theta_k_init = pi/10;
R_init = 7;
rout = 3;
% Define c
c = sqrt(4 – (rout/R_init)^2);
% Define the function for the differential equations
f = @(r, y) [y(2); ((-1*(lambda_init+1)*(r*y(2)+y(1)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1))-(kappa_init*r*y(3)*sin(theta_k_init))+(-16*lambda_init*r^2)/(c^4*R_init^2)); y(4); ((-1*(r*y(4)+y(3)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-1)*y(3))+(kappa_init*r*y(1)*sin(theta_k_init)))];
% Solve the differential equations using ode45
r_span = linspace(0, rout, 100); % Define the range of r values
[~, sol] = ode45(f, r_span, [0, 0, 0, 0]);
% Extract solutions
dr_sol = sol(:,1);
dtheta_sol = sol(:,3);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r_span, dr_sol, ‘b-‘);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Solution of dr(r) vs r’);
subplot(2,1,2);
plot(r_span, dtheta_sol, ‘b-‘);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Solution of dtheta(r) vs r’);
I am trying to solve the coupled differential eqns for d_r(r) vs r and d_theta(r) vs r for these parameter values and boundary conditions so that it is zero at both end d_r(0) = d_r(rout) = 0 and the same for d_theta. However, Not able to see the plot and data. please suggest me errors. % Define initial parameters
lambda_init = 2;
kappa_init = 1;
theta_k_init = pi/10;
R_init = 7;
rout = 3;
% Define c
c = sqrt(4 – (rout/R_init)^2);
% Define the function for the differential equations
f = @(r, y) [y(2); ((-1*(lambda_init+1)*(r*y(2)+y(1)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-(lambda_init+1))*y(1))-(kappa_init*r*y(3)*sin(theta_k_init))+(-16*lambda_init*r^2)/(c^4*R_init^2)); y(4); ((-1*(r*y(4)+y(3)))+(1/r)*((kappa_init*r^2*cos(theta_k_init)-1)*y(3))+(kappa_init*r*y(1)*sin(theta_k_init)))];
% Solve the differential equations using ode45
r_span = linspace(0, rout, 100); % Define the range of r values
[~, sol] = ode45(f, r_span, [0, 0, 0, 0]);
% Extract solutions
dr_sol = sol(:,1);
dtheta_sol = sol(:,3);
% Plot the solutions
figure;
subplot(2,1,1);
plot(r_span, dr_sol, ‘b-‘);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Solution of dr(r) vs r’);
subplot(2,1,2);
plot(r_span, dtheta_sol, ‘b-‘);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Solution of dtheta(r) vs r’);
I am trying to solve the coupled differential eqns for d_r(r) vs r and d_theta(r) vs r for these parameter values and boundary conditions so that it is zero at both end d_r(0) = d_r(rout) = 0 and the same for d_theta. However, Not able to see the plot and data. please suggest me errors. eqn solve, plotting MATLAB Answers — New Questions
Manual and Automatic Image Recognition
I need to identify bright and dark spots in an image, but the contrast of these spots is not very good. Processing the image by taking the maximum and minimum contrast values from a portion of the image is always difficult. Someone told me that defining the circularity of contrast could help identify these spots, and this method is feasible. My code is provided below.
My question is: I want to manually designate a region, and then have the program automatically re-identify the bright and dark spots in the designated area after it finishes identifying the rest of the image. For example, in the image below, is there a way to help me identify the black and white circles? Additionally, I want to apply a Voronoi Diagram to the identified spots in the image.
code:
clc
clear
% read image
inpict = imread(‘image.png’);
inpict = im2gray(inpict);
% logfilter image
t=1;
sigma=sqrt(t);
Fsize = ceil(sigma*3)*2+1;
h1 = fspecial(‘gaussian’,[Fsize,Fsize],sigma);
h2 = fspecial(‘log’,[Fsize,Fsize],sigma);
filter1 = uint8(imfilter(inpict,h1,’replicate’));
filter2 = t * imfilter(inpict, h2, ‘replicate’);
bw = filter2 >=0;
filter2= uint8(filter2 + 128);
figure
subplot(221), imshow(filter1);
title(sprintf(‘filtered by Gaussinan, t =%d’,t));
subplot(222), imshow(filter2, []);
title(sprintf(‘filtered by log, t =%d’,t));
subplot(223), imshow(bw*255);
title(sprintf(‘binarized, t =%d’,t));
%Automatic Image Recognition
inpict = imflatfield(filter1,30); %Flat-field correction of images
inpict = adapthisteq(inpict);
inpict = imresize(inpict, 2);
inpict = imadjust(inpict);
%Automatic Image Recognition (1.Creating Local Extreme Masks)
minex = 30; %black
maxex = 20; %white
maskmx = imextendedmax(inpict, minex); % black
maskmn = imextendedmin(inpict, maxex); % white
% 2.Removal of part of the plaque on the border
maskmx = imclearborder(maskmx);
maskmn = imclearborder(maskmn);
% filtering based on patch attributes
minc = 0.2;
maxecc = 0.87;
minarea = 10;
% Maximum Mask
Lmx = bwlabel(maskmx);
Smx = regionprops(maskmx, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smx.Circularity] >= minc …
& [Smx.Eccentricity] <= maxecc …
& [Smx.Area] >= minarea);
maskmx = any(Lmx == permute(goodblobs, [1 3 2]), 3);
% minimum value mask
Lmn = bwlabel(maskmn);
Smn = regionprops(maskmn, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smn.Circularity] >= minc …
& [Smn.Eccentricity] <= maxecc …
& [Smn.Area] >= minarea);
maskmn = any(Lmn == permute(goodblobs, [1 3 2]), 3);
% Visualisation masks and images
outpict = cat(3, im2uint8(maskmx), im2uint8(maskmn), inpict);
imshow(outpict, ‘border’, ‘tight’);I need to identify bright and dark spots in an image, but the contrast of these spots is not very good. Processing the image by taking the maximum and minimum contrast values from a portion of the image is always difficult. Someone told me that defining the circularity of contrast could help identify these spots, and this method is feasible. My code is provided below.
My question is: I want to manually designate a region, and then have the program automatically re-identify the bright and dark spots in the designated area after it finishes identifying the rest of the image. For example, in the image below, is there a way to help me identify the black and white circles? Additionally, I want to apply a Voronoi Diagram to the identified spots in the image.
code:
clc
clear
% read image
inpict = imread(‘image.png’);
inpict = im2gray(inpict);
% logfilter image
t=1;
sigma=sqrt(t);
Fsize = ceil(sigma*3)*2+1;
h1 = fspecial(‘gaussian’,[Fsize,Fsize],sigma);
h2 = fspecial(‘log’,[Fsize,Fsize],sigma);
filter1 = uint8(imfilter(inpict,h1,’replicate’));
filter2 = t * imfilter(inpict, h2, ‘replicate’);
bw = filter2 >=0;
filter2= uint8(filter2 + 128);
figure
subplot(221), imshow(filter1);
title(sprintf(‘filtered by Gaussinan, t =%d’,t));
subplot(222), imshow(filter2, []);
title(sprintf(‘filtered by log, t =%d’,t));
subplot(223), imshow(bw*255);
title(sprintf(‘binarized, t =%d’,t));
%Automatic Image Recognition
inpict = imflatfield(filter1,30); %Flat-field correction of images
inpict = adapthisteq(inpict);
inpict = imresize(inpict, 2);
inpict = imadjust(inpict);
%Automatic Image Recognition (1.Creating Local Extreme Masks)
minex = 30; %black
maxex = 20; %white
maskmx = imextendedmax(inpict, minex); % black
maskmn = imextendedmin(inpict, maxex); % white
% 2.Removal of part of the plaque on the border
maskmx = imclearborder(maskmx);
maskmn = imclearborder(maskmn);
% filtering based on patch attributes
minc = 0.2;
maxecc = 0.87;
minarea = 10;
% Maximum Mask
Lmx = bwlabel(maskmx);
Smx = regionprops(maskmx, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smx.Circularity] >= minc …
& [Smx.Eccentricity] <= maxecc …
& [Smx.Area] >= minarea);
maskmx = any(Lmx == permute(goodblobs, [1 3 2]), 3);
% minimum value mask
Lmn = bwlabel(maskmn);
Smn = regionprops(maskmn, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smn.Circularity] >= minc …
& [Smn.Eccentricity] <= maxecc …
& [Smn.Area] >= minarea);
maskmn = any(Lmn == permute(goodblobs, [1 3 2]), 3);
% Visualisation masks and images
outpict = cat(3, im2uint8(maskmx), im2uint8(maskmn), inpict);
imshow(outpict, ‘border’, ‘tight’); I need to identify bright and dark spots in an image, but the contrast of these spots is not very good. Processing the image by taking the maximum and minimum contrast values from a portion of the image is always difficult. Someone told me that defining the circularity of contrast could help identify these spots, and this method is feasible. My code is provided below.
My question is: I want to manually designate a region, and then have the program automatically re-identify the bright and dark spots in the designated area after it finishes identifying the rest of the image. For example, in the image below, is there a way to help me identify the black and white circles? Additionally, I want to apply a Voronoi Diagram to the identified spots in the image.
code:
clc
clear
% read image
inpict = imread(‘image.png’);
inpict = im2gray(inpict);
% logfilter image
t=1;
sigma=sqrt(t);
Fsize = ceil(sigma*3)*2+1;
h1 = fspecial(‘gaussian’,[Fsize,Fsize],sigma);
h2 = fspecial(‘log’,[Fsize,Fsize],sigma);
filter1 = uint8(imfilter(inpict,h1,’replicate’));
filter2 = t * imfilter(inpict, h2, ‘replicate’);
bw = filter2 >=0;
filter2= uint8(filter2 + 128);
figure
subplot(221), imshow(filter1);
title(sprintf(‘filtered by Gaussinan, t =%d’,t));
subplot(222), imshow(filter2, []);
title(sprintf(‘filtered by log, t =%d’,t));
subplot(223), imshow(bw*255);
title(sprintf(‘binarized, t =%d’,t));
%Automatic Image Recognition
inpict = imflatfield(filter1,30); %Flat-field correction of images
inpict = adapthisteq(inpict);
inpict = imresize(inpict, 2);
inpict = imadjust(inpict);
%Automatic Image Recognition (1.Creating Local Extreme Masks)
minex = 30; %black
maxex = 20; %white
maskmx = imextendedmax(inpict, minex); % black
maskmn = imextendedmin(inpict, maxex); % white
% 2.Removal of part of the plaque on the border
maskmx = imclearborder(maskmx);
maskmn = imclearborder(maskmn);
% filtering based on patch attributes
minc = 0.2;
maxecc = 0.87;
minarea = 10;
% Maximum Mask
Lmx = bwlabel(maskmx);
Smx = regionprops(maskmx, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smx.Circularity] >= minc …
& [Smx.Eccentricity] <= maxecc …
& [Smx.Area] >= minarea);
maskmx = any(Lmx == permute(goodblobs, [1 3 2]), 3);
% minimum value mask
Lmn = bwlabel(maskmn);
Smn = regionprops(maskmn, ‘circularity’, ‘eccentricity’, ‘area’);
goodblobs = find([Smn.Circularity] >= minc …
& [Smn.Eccentricity] <= maxecc …
& [Smn.Area] >= minarea);
maskmn = any(Lmn == permute(goodblobs, [1 3 2]), 3);
% Visualisation masks and images
outpict = cat(3, im2uint8(maskmx), im2uint8(maskmn), inpict);
imshow(outpict, ‘border’, ‘tight’); image analysis, recognition, graphics, image segmentation, skiz MATLAB Answers — New Questions
Second order coupled differential equation
I need help in solving the second order coupled differential equations as I’m unable to get the right solution after spending many days.
I want to solve it with two for loops (One for frequency and other for Resistance), but unfortunatly it doesnt work well. I would be very happy if someone can help me in this regard.
I am sharing my code to be more precise.
X0 = [0; 0; 0]; % initial conditions
r = linspace(1, 50, 100); % resistance range
freq_vector = linspace(1, 20, 20); % frequency range
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Initialize array to store average power values over frequency range
avgpower_total = zeros(length(freq_vector), length(r));
% Loop over frequencies
for j = 1:length(freq_vector)
w = freq_vector(j); % Current frequency
avgpower = zeros(1, length(r));
tspan = linspace(0,100, 100);
F = 0.8*9.81*cos(w*tspan);
% Loop over resistance values
for i = 1:length(r)
R = r(i); % Current resistance
% Solve ODE using ode45
[t, X] = ode45(@(t, X) VoltResistFun2(t, X, R,F, tspan,w), tspan, X0, options);
% Extraction of voltage value from the solution
Voltage = X(:, 3); % Third state variable
% Calculation of power
P = Voltage.^2 / R;
% Integrated power over time
IntegratedPower = trapz(t, P);
% Calculate average power
avgpower(i) = IntegratedPower / (t(end) – t(1)); % Divide by total time
end
% Store average power for current frequency
avgpower_total(j, 🙂 = avgpower;
% keyboard
end
% Integrate the power over the frequency range and divide by the range
avg_power_over_range = trapz(freq_vector, avgpower_total, 1) / (freq_vector(end) – freq_vector(1));
function dxdt = VoltResistFun2(t, X, R,F, tspan,w)
% Parameters
g = 9.81; % m/s^2
M = 0.01; % proof mass
t_p = 0.01; % thickness
A_p = 0.0001; % area
M_p = 0.00075; % proof mass
E_33 = 1.137e-8; % permittivity
k_33 = 0.75; % electromechanical coupling
e_33 = -1; % value of e_33
m = M + (1/3) * M_p;
C_p = E_33 * A_p / t_p;
theta = -(e_33 * A_p / t_p);
alpha = 1 ./ R;
w0 = 2 * pi * 20;
% F = 0.8 * g*cos(t); % external force
z = 0.02; % damping coefficient
f = interp1(tspan, F.*cos(w*t), t);
% Define state-space matrices
A = [0 1 0; -w0^2 -2*z*w0 -theta/m; 0 theta/C_p -alpha/C_p];
B = [0; -1; 0];
% Calculate derivative of state vector
% keyboard
dxdt = A(X – B*f);
% Ensure dxdt is a column vector
% dxdt = dxdt(:);
end
Note :
eqution1 = x" +2zetaw_0x’ +w_0^2x+theta/m= -F
F is defined
1/R = alpha
Thanks in advanceI need help in solving the second order coupled differential equations as I’m unable to get the right solution after spending many days.
I want to solve it with two for loops (One for frequency and other for Resistance), but unfortunatly it doesnt work well. I would be very happy if someone can help me in this regard.
I am sharing my code to be more precise.
X0 = [0; 0; 0]; % initial conditions
r = linspace(1, 50, 100); % resistance range
freq_vector = linspace(1, 20, 20); % frequency range
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Initialize array to store average power values over frequency range
avgpower_total = zeros(length(freq_vector), length(r));
% Loop over frequencies
for j = 1:length(freq_vector)
w = freq_vector(j); % Current frequency
avgpower = zeros(1, length(r));
tspan = linspace(0,100, 100);
F = 0.8*9.81*cos(w*tspan);
% Loop over resistance values
for i = 1:length(r)
R = r(i); % Current resistance
% Solve ODE using ode45
[t, X] = ode45(@(t, X) VoltResistFun2(t, X, R,F, tspan,w), tspan, X0, options);
% Extraction of voltage value from the solution
Voltage = X(:, 3); % Third state variable
% Calculation of power
P = Voltage.^2 / R;
% Integrated power over time
IntegratedPower = trapz(t, P);
% Calculate average power
avgpower(i) = IntegratedPower / (t(end) – t(1)); % Divide by total time
end
% Store average power for current frequency
avgpower_total(j, 🙂 = avgpower;
% keyboard
end
% Integrate the power over the frequency range and divide by the range
avg_power_over_range = trapz(freq_vector, avgpower_total, 1) / (freq_vector(end) – freq_vector(1));
function dxdt = VoltResistFun2(t, X, R,F, tspan,w)
% Parameters
g = 9.81; % m/s^2
M = 0.01; % proof mass
t_p = 0.01; % thickness
A_p = 0.0001; % area
M_p = 0.00075; % proof mass
E_33 = 1.137e-8; % permittivity
k_33 = 0.75; % electromechanical coupling
e_33 = -1; % value of e_33
m = M + (1/3) * M_p;
C_p = E_33 * A_p / t_p;
theta = -(e_33 * A_p / t_p);
alpha = 1 ./ R;
w0 = 2 * pi * 20;
% F = 0.8 * g*cos(t); % external force
z = 0.02; % damping coefficient
f = interp1(tspan, F.*cos(w*t), t);
% Define state-space matrices
A = [0 1 0; -w0^2 -2*z*w0 -theta/m; 0 theta/C_p -alpha/C_p];
B = [0; -1; 0];
% Calculate derivative of state vector
% keyboard
dxdt = A(X – B*f);
% Ensure dxdt is a column vector
% dxdt = dxdt(:);
end
Note :
eqution1 = x" +2zetaw_0x’ +w_0^2x+theta/m= -F
F is defined
1/R = alpha
Thanks in advance I need help in solving the second order coupled differential equations as I’m unable to get the right solution after spending many days.
I want to solve it with two for loops (One for frequency and other for Resistance), but unfortunatly it doesnt work well. I would be very happy if someone can help me in this regard.
I am sharing my code to be more precise.
X0 = [0; 0; 0]; % initial conditions
r = linspace(1, 50, 100); % resistance range
freq_vector = linspace(1, 20, 20); % frequency range
options = odeset(‘RelTol’, 1e-6, ‘AbsTol’, 1e-6);
% Initialize array to store average power values over frequency range
avgpower_total = zeros(length(freq_vector), length(r));
% Loop over frequencies
for j = 1:length(freq_vector)
w = freq_vector(j); % Current frequency
avgpower = zeros(1, length(r));
tspan = linspace(0,100, 100);
F = 0.8*9.81*cos(w*tspan);
% Loop over resistance values
for i = 1:length(r)
R = r(i); % Current resistance
% Solve ODE using ode45
[t, X] = ode45(@(t, X) VoltResistFun2(t, X, R,F, tspan,w), tspan, X0, options);
% Extraction of voltage value from the solution
Voltage = X(:, 3); % Third state variable
% Calculation of power
P = Voltage.^2 / R;
% Integrated power over time
IntegratedPower = trapz(t, P);
% Calculate average power
avgpower(i) = IntegratedPower / (t(end) – t(1)); % Divide by total time
end
% Store average power for current frequency
avgpower_total(j, 🙂 = avgpower;
% keyboard
end
% Integrate the power over the frequency range and divide by the range
avg_power_over_range = trapz(freq_vector, avgpower_total, 1) / (freq_vector(end) – freq_vector(1));
function dxdt = VoltResistFun2(t, X, R,F, tspan,w)
% Parameters
g = 9.81; % m/s^2
M = 0.01; % proof mass
t_p = 0.01; % thickness
A_p = 0.0001; % area
M_p = 0.00075; % proof mass
E_33 = 1.137e-8; % permittivity
k_33 = 0.75; % electromechanical coupling
e_33 = -1; % value of e_33
m = M + (1/3) * M_p;
C_p = E_33 * A_p / t_p;
theta = -(e_33 * A_p / t_p);
alpha = 1 ./ R;
w0 = 2 * pi * 20;
% F = 0.8 * g*cos(t); % external force
z = 0.02; % damping coefficient
f = interp1(tspan, F.*cos(w*t), t);
% Define state-space matrices
A = [0 1 0; -w0^2 -2*z*w0 -theta/m; 0 theta/C_p -alpha/C_p];
B = [0; -1; 0];
% Calculate derivative of state vector
% keyboard
dxdt = A(X – B*f);
% Ensure dxdt is a column vector
% dxdt = dxdt(:);
end
Note :
eqution1 = x" +2zetaw_0x’ +w_0^2x+theta/m= -F
F is defined
1/R = alpha
Thanks in advance ode45, second order coupled equations, energy harvester, avg power calculation MATLAB Answers — New Questions
Could you help with deleting a resource in the Storage Account ?
Hello,
Could you please help me on how to delete a resource in my Storage Account? I tried to delete the selecting resource in the Storage Account but it keeps saying that I have a resource block.
I don’t know how to unlock the resource in order to delete it. Could you help?
Below is the selected resource that I tried to delete.
Hello, Could you please help me on how to delete a resource in my Storage Account? I tried to delete the selecting resource in the Storage Account but it keeps saying that I have a resource block.I don’t know how to unlock the resource in order to delete it. Could you help?Below is the selected resource that I tried to delete. Read More
Partner Blog | Microsoft Build 2024: Empowering Partners through AI and Cloud Innovation
Microsoft Tech Community – Latest Blogs –Read More
Public Preview: App Service Authentication Logs on Diagnostic Settings
A new log “AppServiceAuthenticationLogs” is now available in Public Preview for App Service resources on Windows. This would include Web Apps, Functions, and Logic Apps. If you would like to have more visibility into your App Service Authentication and would like to troubleshoot or self-diagnose issues, you can enable this log category to help with these scenarios.
App Service Linux resources and Functions Consumption Plan (Linux and Windows) currently does not support this log. You may still see this log as an option in the Diagnostic Settings. However, if your resource is one of the unsupported scenarios, you will not see any logs despite enabling “AppServiceAuthenticationLogs”.
Like any Diagnostic Settings logs, this log could be enabled via Diagnostic Settings and will show up as “App Service Authentication Logs”. However, one important difference from the previous logs is that “AppServiceAuthenticationLogs” would be charged for the cost to export logs to various endpoints, in addition to the cost of using the endpoints (ie. Storage, Log Analytics). You can find more information on platform logs export pricing and a list of exportable logs on App Service.
The next section of the article will go more in depth into the different logs that will be emitted and will provide you with a better understanding about each log.
Supported Logs
AppServiceAuthenticationLogs currently will only generate “Warning” and “Error” logs. No logs will be generated for successful App Service Authentication requests.
Log Messages
This section contains additional information for common Warning and Error logs that may be helpful for diagnosing potential issues. Please note that any suggested actions are only recommendations and that individual scenarios may differ.
Warning Logs
Message
Comment/Recommendation
JWT validation failed:
Audience validation failure
May occur if the audience parameter in the incoming token is not specified as an allowed audience in your configuration, resulting in a 401 response code. The audience parameter specifies the resource that the token grants access to and typically should be the Client Id of your web app.
IDX12741: JWT: ‘[PII of type ‘System.String’ is hidden. For more details, see https://aka.ms/IdentityModel/PII.]’ must have three segments (JWS) or five segments (JWE)..
Indicates an incorrectly formatted JWT token that may result in a 401 response code.
Principal (isUser: False) failed single tenancy check for single tenant AAD app.
Indicates that the incoming token did not come from the same tenant as the AAD application and there may be issues with single-tenancy.
An authenticated principal (userhash: ***) for an API call failed authorization.
——————————-
An authenticated principal (userhash: ***) for an API call has a cached failed authorization check.
Expected to occur if the incoming token should not have access to the resource and will result in a 403 response code. If this is unexpected, then the authorization policies in your configuration may be incorrectly defined (check the allowed principals, allowed applications, and allowed tenants properties).
Login token for ‘***’ was rejected because contained an invalid ‘nonce’ claim.
——————————-
Login token for ‘***’ was rejected because it did not contain a ‘nonce’ claim.
——————————-
Failed to read the ‘Nonce’ cookie for site ‘***’
May occur if the login session takes too long to complete. The nonce claim is associated with the login session and will expire after a set time. If this occurs, attempt login again.
Access was denied for ‘***’ because this principal does not match any of the allowed applications.
——————————-
Access was denied for ‘***’ because this principal does not match any of the principal policies.
——————————-
Access was denied for ‘***’ because this principal does not match any of the allowed tenants.
Expected to occur if the incoming token should not have access to the resource and will result in a 403 response code. If this is unexpected, then check that the relevant property (allowed principals, allowed applications, or allowed tenants) match the principal claims in the token.
Error Logs
Message
Comment/Recommendation
HTTP proxy request encountered exception.
Type: System.Net.Http.HttpRequestException
Message: Connection refused
——————————-
HTTP proxy request encountered exception.
Type: System.Net.Http.HttpRequestException
Message: Connection timed out
Indicates that a request forwarding attempt failed and may manifest as a 5xx response code. A starting point is to investigate application logs to see why the request failed. For example, running extra containers or added load can result in latency due to resource contention.
An error occurred while monitoring the file system: System.IO.InternalBufferOverflowException: Too many changes at once in directory:C:homedata.authtokens.
May occur if your application has too much load; for example, if there are too many writes at a given time. Blob storage can be used instead of file storage to mitigate, trading more reliable storage for more writes. Can also disable token store if not needed.
Failed to download OpenID configuration from ‘***’
Occurs when an HTTP request to the Open ID configuration endpoint fails and may manifest with a 500 response code. This is sometimes transient, as a failed request will trigger another attempt and retries may succeed. If this error is consistently occurring, check that the Open ID endpoint specified in your configuration is correct and accessible from the context of your web app.
Failed to read the ‘AppServiceAuthSession’ cookie for site ‘***’: The signature of the encrypted data is invalid.
——————————-
Failed to read the ‘AppServiceAuthSession’ cookie for site ‘***’: Invalid length for a Base-64 char array or string.
——————————-
Failed to read the ‘AppServiceAuthSession’ cookie for site ‘***’: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.
Indicates a problem with validating or decrypting the session cookie. This may occur if there is an issue with encryption key rotation or the session cookie is malformed and may require logging in again.
Microsoft Tech Community – Latest Blogs –Read More
Cannot load python library with R2024a: API functions not available
I updated MATLAB to R2024a a few days ago, and I’m now trying the basic example to call Python from MATLAB here: https://ch.mathworks.com/help/matlab/call-python-libraries.html
I tried the following:
>> py.list
and see this error immediately:
Python API functions are not available.
I have the PythonEnvironment setup as follows:
>> pyversion(‘/Users/…/opt/anaconda3/bin/python’)
>> pyenv
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/…/opt/anaconda3/bin/python"
Library: "/Users/…/opt/anaconda3/lib/libpython3.9.dylib"
Home: "/Users/…/opt/anaconda3"
Status: NotLoaded
ExecutionMode: OutOfProcess
It appears I cannot get the status to turn to "Loaded", which used to happen earlier with R2023b. I am also using the apple silicon native version (maca64) of MATLAB, which could also be a factor here. I read https://ch.mathworks.com/matlabcentral/answers/1977529-how-to-use-python-from-matlab-on-mac-with-apple-silicon and have installed Amazon Corretto 11 from here: https://ch.mathworks.com/support/requirements/apple-silicon.html
Any idea how I could get the Python API to load? Many thanks in advance for your help!I updated MATLAB to R2024a a few days ago, and I’m now trying the basic example to call Python from MATLAB here: https://ch.mathworks.com/help/matlab/call-python-libraries.html
I tried the following:
>> py.list
and see this error immediately:
Python API functions are not available.
I have the PythonEnvironment setup as follows:
>> pyversion(‘/Users/…/opt/anaconda3/bin/python’)
>> pyenv
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/…/opt/anaconda3/bin/python"
Library: "/Users/…/opt/anaconda3/lib/libpython3.9.dylib"
Home: "/Users/…/opt/anaconda3"
Status: NotLoaded
ExecutionMode: OutOfProcess
It appears I cannot get the status to turn to "Loaded", which used to happen earlier with R2023b. I am also using the apple silicon native version (maca64) of MATLAB, which could also be a factor here. I read https://ch.mathworks.com/matlabcentral/answers/1977529-how-to-use-python-from-matlab-on-mac-with-apple-silicon and have installed Amazon Corretto 11 from here: https://ch.mathworks.com/support/requirements/apple-silicon.html
Any idea how I could get the Python API to load? Many thanks in advance for your help! I updated MATLAB to R2024a a few days ago, and I’m now trying the basic example to call Python from MATLAB here: https://ch.mathworks.com/help/matlab/call-python-libraries.html
I tried the following:
>> py.list
and see this error immediately:
Python API functions are not available.
I have the PythonEnvironment setup as follows:
>> pyversion(‘/Users/…/opt/anaconda3/bin/python’)
>> pyenv
ans =
PythonEnvironment with properties:
Version: "3.9"
Executable: "/Users/…/opt/anaconda3/bin/python"
Library: "/Users/…/opt/anaconda3/lib/libpython3.9.dylib"
Home: "/Users/…/opt/anaconda3"
Status: NotLoaded
ExecutionMode: OutOfProcess
It appears I cannot get the status to turn to "Loaded", which used to happen earlier with R2023b. I am also using the apple silicon native version (maca64) of MATLAB, which could also be a factor here. I read https://ch.mathworks.com/matlabcentral/answers/1977529-how-to-use-python-from-matlab-on-mac-with-apple-silicon and have installed Amazon Corretto 11 from here: https://ch.mathworks.com/support/requirements/apple-silicon.html
Any idea how I could get the Python API to load? Many thanks in advance for your help! python MATLAB Answers — New Questions
The “parfeval” command is not working on the addPath function
I have a cell array that contains the folder paths that I want to add to the project path. Initially, I used the clasic for loop; however, as the cell array contains more than 2K folder paths, this clasic for loop takes more than 2 hours to complete the task. To overcome this issue, I have used the "parfeval" command in the for loop, but I am getting the error mentioned below.
Error Details:
Caused by:
Error using matlab.project.Project/addPath
Dot indexing is not supported for variables of this type.
How can i resolve this issue?
Below is my code:
%get current project
proj_modelBasedDesignCodeGen = currentProject;
% List of folder paths
FolderPaths = {‘componentsComponentA’, ‘componentsComponentB’, ‘componentsComponentC’, ‘componentsComponentD’};
% Preallocate cell array to store output
futures = cell(1, numel(FolderPaths));
% Loop through each folder path and submit a task to the parallel pool
for i = 1:numel(FolderPaths)
inputFolder = FolderPaths{i};
% Use parfeval to asynchronously evaluate function addPath
futures{i}= parfeval(@addPath, 1,proj_modelBasedDesignCodeGen, inputFolder); % 1 is the number of output arguments
endI have a cell array that contains the folder paths that I want to add to the project path. Initially, I used the clasic for loop; however, as the cell array contains more than 2K folder paths, this clasic for loop takes more than 2 hours to complete the task. To overcome this issue, I have used the "parfeval" command in the for loop, but I am getting the error mentioned below.
Error Details:
Caused by:
Error using matlab.project.Project/addPath
Dot indexing is not supported for variables of this type.
How can i resolve this issue?
Below is my code:
%get current project
proj_modelBasedDesignCodeGen = currentProject;
% List of folder paths
FolderPaths = {‘componentsComponentA’, ‘componentsComponentB’, ‘componentsComponentC’, ‘componentsComponentD’};
% Preallocate cell array to store output
futures = cell(1, numel(FolderPaths));
% Loop through each folder path and submit a task to the parallel pool
for i = 1:numel(FolderPaths)
inputFolder = FolderPaths{i};
% Use parfeval to asynchronously evaluate function addPath
futures{i}= parfeval(@addPath, 1,proj_modelBasedDesignCodeGen, inputFolder); % 1 is the number of output arguments
end I have a cell array that contains the folder paths that I want to add to the project path. Initially, I used the clasic for loop; however, as the cell array contains more than 2K folder paths, this clasic for loop takes more than 2 hours to complete the task. To overcome this issue, I have used the "parfeval" command in the for loop, but I am getting the error mentioned below.
Error Details:
Caused by:
Error using matlab.project.Project/addPath
Dot indexing is not supported for variables of this type.
How can i resolve this issue?
Below is my code:
%get current project
proj_modelBasedDesignCodeGen = currentProject;
% List of folder paths
FolderPaths = {‘componentsComponentA’, ‘componentsComponentB’, ‘componentsComponentC’, ‘componentsComponentD’};
% Preallocate cell array to store output
futures = cell(1, numel(FolderPaths));
% Loop through each folder path and submit a task to the parallel pool
for i = 1:numel(FolderPaths)
inputFolder = FolderPaths{i};
% Use parfeval to asynchronously evaluate function addPath
futures{i}= parfeval(@addPath, 1,proj_modelBasedDesignCodeGen, inputFolder); % 1 is the number of output arguments
end parallel computing MATLAB Answers — New Questions
How to re-generate script from already built workspace
I am having some difficulty in finding my script for several differential equations solution. Please someone help me in how to regenerate MATLAB script from workspace because i have variable workspace. when i first loaded the script it was saved in workspace format and i can not retrieve the script again because of lack of experienceI am having some difficulty in finding my script for several differential equations solution. Please someone help me in how to regenerate MATLAB script from workspace because i have variable workspace. when i first loaded the script it was saved in workspace format and i can not retrieve the script again because of lack of experience I am having some difficulty in finding my script for several differential equations solution. Please someone help me in how to regenerate MATLAB script from workspace because i have variable workspace. when i first loaded the script it was saved in workspace format and i can not retrieve the script again because of lack of experience script, workspace, homework MATLAB Answers — New Questions
Does MPC without constraints also solves QP problem? How to check QP solver within matlab?
Hi, I have one confusion about MPC controller, usually the cost function is minimized by solving QP problem at each time step.
Is MPC solves QP problem only when we have constraints or unconstraint’s MPC the optimal U is find by solving QP problem? and How to check in MATLAB that MPC is solving QP or not?Hi, I have one confusion about MPC controller, usually the cost function is minimized by solving QP problem at each time step.
Is MPC solves QP problem only when we have constraints or unconstraint’s MPC the optimal U is find by solving QP problem? and How to check in MATLAB that MPC is solving QP or not? Hi, I have one confusion about MPC controller, usually the cost function is minimized by solving QP problem at each time step.
Is MPC solves QP problem only when we have constraints or unconstraint’s MPC the optimal U is find by solving QP problem? and How to check in MATLAB that MPC is solving QP or not? model predictive control, mpc, optimization problem, qp problem MATLAB Answers — New Questions
Equivalent license to Power Apps Portals, as the latter has expired
Hello,
We have a customer with the following license: Power Apps Portals login capacity add-on Tier 2 (10 unit min) for Faculty, which expired on its renewal date and can no longer be reactivated.
Is there currently a license different from Power Pages that is equivalent to Power Apps Portals so we can activate it for the client?
The problem with Power Pages is that migration from Portals to Pages cannot be done immediately, requiring development hours, so we want to know if there is any license that does not require this extra work.
Hello, We have a customer with the following license: Power Apps Portals login capacity add-on Tier 2 (10 unit min) for Faculty, which expired on its renewal date and can no longer be reactivated. Is there currently a license different from Power Pages that is equivalent to Power Apps Portals so we can activate it for the client? The problem with Power Pages is that migration from Portals to Pages cannot be done immediately, requiring development hours, so we want to know if there is any license that does not require this extra work. Read More
Excel view with some spreadsheets within teams
HELP….When I open excel files that open in a browser it looks like this. When I place my cursor in a certain cell it appears normal in the preview cell at the top. If I save the file on my desktop it seems to fix the issue. It is a shared file and it looks fine when others open it …Please help me fix this. THX
HELP….When I open excel files that open in a browser it looks like this. When I place my cursor in a certain cell it appears normal in the preview cell at the top. If I save the file on my desktop it seems to fix the issue. It is a shared file and it looks fine when others open it …Please help me fix this. THX Read More
Teams Rooms Licenses Rug Pulled and New Licenses Don’t work.
Im so annoyed right now. We lost our “Teams Room Standard” licenses out of the blue from Techdata. So we got our 25 Teams Room Basic Licenses. Applied them to the rooms, and now they don’t work at all. GD Microsoft paywalling and rug pulling licenses all the time is becoming problematic. What’s next? Is Microsoft going to make me have a license to use USB devices? License me per monitor? Freaking unreal how my 8k rooms are dead stick because of this stupid BS. I’m not calling support to get some tier 1 idiot who is going to make me fill out a 10 question email about nothing related to this and not hear back for a week. I need this fixed now. I didn’t break it, you did Microsoft — fix it and update your worthless documents too. Resolution is a joke…
Im so annoyed right now. We lost our “Teams Room Standard” licenses out of the blue from Techdata. So we got our 25 Teams Room Basic Licenses. Applied them to the rooms, and now they don’t work at all. GD Microsoft paywalling and rug pulling licenses all the time is becoming problematic. What’s next? Is Microsoft going to make me have a license to use USB devices? License me per monitor? Freaking unreal how my 8k rooms are dead stick because of this stupid BS. I’m not calling support to get some tier 1 idiot who is going to make me fill out a 10 question email about nothing related to this and not hear back for a week. I need this fixed now. I didn’t break it, you did Microsoft — fix it and update your worthless documents too. Resolution is a joke…https://learn.microsoft.com/en-us/microsoftteams/troubleshoot/teams-rooms-and-devices/teams-rooms-resource-account-sign-in-issues#resolution Read More
Copilot for Sales Outlook addin error
I have admin-deployed Copilot for Sales via M365 Intergrated App process. After about a week, we started getting dozens of users with an error message in the sidepane within Outlook. It simply states “We can’t start this add-in because it isn’t set up properly.”
I have tried to compare users who have the issue vs users who don’t have the issue, but they appear to be on the same versions of Outlook (16.0.17531.20152). The addin was deployed on May 9th and issues started coming in around May 20th and I can’t seem to find any rhyme or reason to some users error. What is also confusing is the addin technically “works”, it just constantly is generating that error every time they open a new email
I have admin-deployed Copilot for Sales via M365 Intergrated App process. After about a week, we started getting dozens of users with an error message in the sidepane within Outlook. It simply states “We can’t start this add-in because it isn’t set up properly.” I have tried to compare users who have the issue vs users who don’t have the issue, but they appear to be on the same versions of Outlook (16.0.17531.20152). The addin was deployed on May 9th and issues started coming in around May 20th and I can’t seem to find any rhyme or reason to some users error. What is also confusing is the addin technically “works”, it just constantly is generating that error every time they open a new email Read More
Introducing Personal Data Encryption for developers
Personal Data Encryption (PDE) along with BitLocker constitutes Windows data protection on Windows devices. BitLocker is a Windows security feature that provides encryption for entire volumes, addressing the threats of data theft or exposure from lost, stolen, or inappropriately decommissioned devices. However, there are some cases in which BitLocker protection alone might not be sufficient. For example, Trusted Platform Module (TPM) bus sniffing, targeting devices that do not have BitLocker TPM + PIN options set, or trying to get encryption keys by sniffing the unsecured bus between the CPU and TPM can all put BitLocker protected personal data at risk. Direct Memory Access (DMA) based drive-by attacks target devices with unsecured DMA ports and work by bypassing the sign in and getting directly to the end user’s data. Applications and browsers that utilize AI to power recommendation engines capture sensitive user data and also need to be protected.
PDE provides an extra layer of security, in addition to that provided by BitLocker, for when the device is locked and powered on, protecting it from sophisticated physical attacks. PDE uses Windows Hello for Business to link data encryption keys with user credentials. When a user signs in to a device using Windows Hello for Business, decryption keys are released, and encrypted data is accessible to the user. It’s important to note that PDE and BitLocker are not dependent on each other. PDE can be used with or without any other full disk encryption solutions, although it is highly recommended to use both.
PDE API offers a comprehensive and extensible set of low-level APIs for the protection of end-user content. These APIs enable the encryption of end-user data, and the keys used for encryption are protected by the user’s Windows Hello credentials. It is important to note that PDE is exclusively available in Windows Enterprise and Education editions.
Content-generating applications can use the PDE API to protect content for two levels of security:
L1 (AfterFirstUnlock) level of protection: Data protected to this level is accessible only after the first device unlock, and it will continue to be available thereafter.
L2 (WhileUnlocked) level protection: Data protected to this level is only available when the device is unlocked and provides additional protection.
Now let’s look at how an application that generates content can use PDE API to protect files, folders, and buffers.
Use cases for PDE API
PDE API provides a feature set for app developers building Windows applications that generate or modify end-user content on Windows devices.
Industries such as defense, banking, healthcare, and insurance are just some examples of commercial environments that handle a lot of sensitive data and need additional protection to help ensure data security.
Note: PDE is also applied to all content within the known Windows folders such as Documents, Desktop and Pictures that have the L1 level of protection and are available as part of the OS, enabled as a Microsoft Intune policy. This new feature will be available in Windows 11, version 24H2, which is currently available in the Windows Insider Program via the Release Preview Channel.
Using the PDE API
Before getting started, PDE needs to be enabled on the device being used for development using the PDE API. PDE is enabled by policy from a Microsoft Device Management solution like Intune to a group of users in an organization by the IT admin. For more details, see our PDE documentation and our documentation on PDE with the Data Protection API.
Below, we outline a sample application that uses the different functions in the PDE API and the possible scenarios in which they can be used. As shown in the screenshot below, the application walks through protecting folders, files, and text (buffers) with two levels of security as well as unprotecting them. The complete code is available on GitHub.
Packages or libraries to import to start using PDE API in applications
Since PDE API is a Windows Runtime API, integrating it into a project requires some initial steps, as outlined in this article about Windows Runtime APIs. When set up is complete, ensure that Microsoft.Windows.SDK.Contracts package (latest stable version) is installed through the Nuget Package Manager.
The library Microsoft.Windows.SDK.Contracts is installed using the Nuget Package Manager, and then you can import Windows.Security.DataProtection library into code.
<code>
using Windows.Security.DataProtection;
</code>
Windows.Security.DataProtection namespace contains different classes that provide methods to protect/unprotect files and buffers, provide information about availability of the storage item, and provide the status of unprotecting a buffer and callback methods to block/unblock future events.
Global variables in code
Below is the set of global variables that are referenced in code:
UserDataProtectionManager dataProtectionManager;
String selectedFolder = String.Empty;
String selectedFile = String.Empty;
Protecting a folder or file using functions in Windows.Security.DataProtection
The DataProtection namespace provides the UserDataProtectionManager class. When instantiated, this class provides static methods to protect/unprotect folders, files, and buffers.
<code>
dataProtectionManager = UserDataProtectionManager.TryGetDefault();
</code>
The TryGetDefault() method called on the UserDataProtectionManager returns an instance of this class for the current user. The returned instance, if null, means that the PDE policy is not yet enabled on the device or PDE is not supported on the device.
ProtectStorageItemAsync (IStorageItem, UserDataAvailability) is the method used to protect files andfolders. The method takes two parameters: IStorageItem object, which is an encapsulation of a path, and UserDataAvailability object, which is an Enum representing the availability of the protected data. ProtectStorageItemAsync protects one storage item at a time. If the path represents a folder, the onus for recursively protecting all the files and subfolders is on the application. The folder needs to be protected before its contents are. This ensures that any item that is added to the folder later will automatically be protected to the same level as the parent. The code for it could look something like the code snippet below.
Note: It is a security best practice to always encrypt files and folders before data is written to them especially if at startup the OS detects that PDE is available. If PDE is available, the app should protect the folder where it caches its data and protect any file it creates before writing any data if the file isn’t in a folder that is already protected.
Folder or file protection
Please note the call to the ProtectAndLog to protect the folder before protecting all the files in the folder ensures any new additions are automatically protected. The difference between protecting a file or folder is the IStorageItem that gets created. Once an item is created, it is the same ProtectStorageItemSync method that is called for protecting both the file and folder.
<code>
async void ProtectAndLog(IStorageItem item, UserDataAvailability level)
{
try
{
var protectResult = await dataProtectionManager.ProtectStorageItemAsync(item, level);
if (protectResult == UserDataStorageItemProtectionStatus.Succeeded)
{
LogLine(“Protected ” + item.Name + ” to level ” + level);
}
else
{
LogLine(“Protection failed for ” + item.Name + ” to level ” + level + “, status: ” + protectResult);
}
}
catch (NullReferenceException)
{
LogLine(“PDE not enabled on the device, please enable before proceeding!!”);
}
}
async void ProtectFolderRecursively(StorageFolder folder, UserDataAvailability level)
{
// Protect the folder first so new files / folders after this point will
// get protected automatically.
ProtectAndLog(folder, level);
// Protect all sub-folders recursively.
var subFolders = await folder.GetFoldersAsync();
foreach (var subFolder in subFolders)
{
ProtectFolderRecursively(subFolder, level);
}
// Finally protect all existing files in the folder.
var files = await folder.GetFilesAsync();
foreach (var file in files)
{
ProtectAndLog(file, level);
}
}</code>
Folder or file protection status
UserDataStorageItemProtectionStatus is an enum that is populated with the result of the Protect call. This enum is used in the above example to log the appropriate result. The other values in this enum are:
DataUnavailable (2): Requested protection cannot be applied because the data are currently unavailable. For example, changing availability from “WhileUnlocked” to “AfterFirstUnlock” is not possible while the device is locked.
NotProtectable (1): The system does not support protection of the specified storage item.
Further exploring the properties of a protected file gives the end user a view of the availability level to which the file is PDE protected. It also provides information about the On/Off status of Personal Data Encryption.
Protecting buffers using functions in Windows.Security.DataProtection
Along with files, systems also store data in buffers as part of processing. If not protected, these buffers can lead to compromises in security. Buffers in scope are the ones that are persisted.
The ProtectBufferAsync method takes as input the buffer object (any object that implements iBuffer interface) and the level (Enum UserDataAvailability) to which the buffer would need to be protected.
Note: PDE doesn’t protect streams directly. The application will have to protect them in chunks.
The text in the sample below represents a string from any source:
<code>
async void ProtectBuffer(String text, UserDataAvailability level)
{
// Empty buffers cannot be protected, please ensure that text length is not zero.
if (text.Length == 0)
{
return;
}
try
{
var buffer = CryptographicBuffer.ConvertStringToBinary(text, BinaryStringEncoding.Utf8);
var protectedContent = await dataProtectionManager.ProtectBufferAsync(buffer, level);
String protectbase64EncodedContent = CryptographicBuffer.EncodeToBase64String(protectedContent);
bufferOutputTextBox.Text = protectbase64EncodedContent;
LogLine(“Protected buffer: ” + protectbase64EncodedContent);
}
catch (NullReferenceException nrex)
{
LogLine(“PDE not enabled on the device, please enable before proceeding!!”);
LogLine(nrex.ToString());
} }
</code>
Unprotecting files and buffers
The UserDataAvailability enum that sets the protection has three levels:
0: User data is unprotected
1: Data is protected until the first device sign in/unlock and will be unprotected after that
2: Data is protected until first device sign in and when the device screen is locked, and available at other times.
Based on these availability levels, a file can be unprotected by changing the UserDataAvailability value to 0. The unprotection method for buffers is explicit because the buffers are not available when protected, so there is a function in the API for unprotecting the buffer.
<code>
async void UnprotectBuffer(String g_protectbase64EncodedContent)
{
var protectedBuffer = CryptographicBuffer.DecodeFromBase64String(protectbase64EncodedContent);
try
{
var result = await dataProtectionManager.UnprotectBufferAsync(protectedBuffer);
if (result.Status == UserDataBufferUnprotectStatus.Succeeded)
{
String unprotectedText = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, result.UnprotectedBuffer);
LogLine(“Result of Unprotecting the buffer:” + unprotectedText
);
bufferOutputTextBox.Text = “”;
bufferOutputTextBox.Text = unprotectedText;
LogLine(“Status of Unprotecting the buffer:” + result.Status);
}
else
{
LogLine(“This protected buffer is currently unavailable for unprotection”);
}
}
catch(NullReferenceException nrex)
{
LogLine(“PDE not enabled on the device, please enable before proceeding!!”);
LogLine(nrex.ToString());
}
catch(Exception ex)
{
LogLine(“Please verify first the input text provided for unprotecting!”);
LogLine(ex.ToString());
} }
</code>
Buffer unprotection statuses
UserDataBufferUnprotectStatus is the enum that carries the status of unprotection performed on the buffer. In the example above, this status is used to log the appropriate status. There are two members in this enum:
Succeeded(0): Unprotecting the provided buffer succeeded and the result buffer is available in UnprotectedBuffer member
Unavailable(1): Unprotecting the provided buffer is not possible as the protected data is currently unavailable.
Below is the code snippet on how to listen to the event. In this example, the event is listened to when the form is loaded.
<code>
private void Form2_load(object sender, EventArgs e)
{
dataProtectionManager = UserDataProtectionManager.TryGetDefault();
if (dataProtectionManager == null)
{
LogLine(“Personal Data Encryption is not supported or enabled. Restart this app to check again.”);
}
else
{
LogLine(“Personal Data Encryption is enabled.”);
dataProtectionManager.DataAvailabilityStateChanged += (s, M_udpm_DataAvailabilityStateChanged) => {
LogCurrentDataAvailability();
LogLine(“Listening to DataAvailabilityStateChanged event”);
};
} }
private void M_udpm_DataAvailabilityStateChanged(UserDataProtectionManager sender, UserDataAvailabilityStateChangedEventArgs args)
{
LogLine(“DataAvailabilityStateChanged event received”);
LogCurrentDataAvailability();
}
</code>
This class is earmarked for future updates of the API.
Continue the conversation. Find best practices. Bookmark the Windows Tech Community, then follow us @MSWindowsITPro on X and on LinkedIn. Looking for support? Visit Windows on Microsoft Q&A.
Microsoft Tech Community – Latest Blogs –Read More
How to get the screen size where the current uifigure is located?
I want to capture the current uifigure while running, and I have test the function with this demo code.
there is one issue should to be solved: the Y postion from the demo code is base on the left top corner, but the Y position get from uifigure.positon is based on the left bottom corner. So it need to be converted to suit for the code. So my question is how to get the screen size where the active uifigure is located in the multiple screens?
(get(0,’screensize’) can’t get the secondary screen size)
other answers which can capture the active uifigure is also welcome!I want to capture the current uifigure while running, and I have test the function with this demo code.
there is one issue should to be solved: the Y postion from the demo code is base on the left top corner, but the Y position get from uifigure.positon is based on the left bottom corner. So it need to be converted to suit for the code. So my question is how to get the screen size where the active uifigure is located in the multiple screens?
(get(0,’screensize’) can’t get the secondary screen size)
other answers which can capture the active uifigure is also welcome! I want to capture the current uifigure while running, and I have test the function with this demo code.
there is one issue should to be solved: the Y postion from the demo code is base on the left top corner, but the Y position get from uifigure.positon is based on the left bottom corner. So it need to be converted to suit for the code. So my question is how to get the screen size where the active uifigure is located in the multiple screens?
(get(0,’screensize’) can’t get the secondary screen size)
other answers which can capture the active uifigure is also welcome! capture, screen size, get screen size MATLAB Answers — New Questions
Getting screen resolution on Windows 11
Are there other functions I can use to get the monitor resolution on Windows 11? I use this code:
set(0, ‘units’, ‘pixels’); % Sets the units of your root object (screen) to pixels
Pix_SS = get(0, ‘screensize’); % Obtains the pixel information
And all I get is 1920 x 1080? This Dell U4320Q is 3840 x 2160 as shown in this Settings > Display resolution:Are there other functions I can use to get the monitor resolution on Windows 11? I use this code:
set(0, ‘units’, ‘pixels’); % Sets the units of your root object (screen) to pixels
Pix_SS = get(0, ‘screensize’); % Obtains the pixel information
And all I get is 1920 x 1080? This Dell U4320Q is 3840 x 2160 as shown in this Settings > Display resolution: Are there other functions I can use to get the monitor resolution on Windows 11? I use this code:
set(0, ‘units’, ‘pixels’); % Sets the units of your root object (screen) to pixels
Pix_SS = get(0, ‘screensize’); % Obtains the pixel information
And all I get is 1920 x 1080? This Dell U4320Q is 3840 x 2160 as shown in this Settings > Display resolution: windows 11, monitor resolution, 4k MATLAB Answers — New Questions
Problem with the fitting
% Define the data
dr_data = [2.5453, 0.042123; 5.0907, 0.075326; 7.636, 0.059506; 10.1813, 0.071553; 12.7267, 0.071365; 15.272, 0.067195; 17.8173, 0.046372; 20.3627, 0.043397; 22.908, 0.017179; 25.4533, -0.0063329; 27.9987, -0.030789; 30.544, -0.047569; 33.0893, -0.089512; 35.6347, -0.080675; 38.18, -0.089138; 40.7253, -0.1102; 43.2707, -0.12061; 45.816, -0.11857; 48.3613, -0.11955; 50.9067, -0.10803; 53.452, -0.10462; 55.9973, -0.099548; 58.5427, -0.097164; 61.088, -0.09994; 63.6333, -0.077017; 66.1787, -0.062839; 68.724, -0.048422; 71.2693, -0.03686; 73.8147, -0.01469; 76.3, 0];
dtheta_data = [2.5453, -0.099251; 5.0907, -0.16064; 7.636, -0.21858; 10.1813, -0.18965; 12.7267, -0.16996; 15.272, -0.18172; 17.8173, -0.15029; 20.3627, -0.12541; 22.908, -0.082786; 25.4533, -0.0071716; 27.9987, 0.03695; 30.544, 0.089002; 33.0893, 0.12873; 35.6347, 0.13092; 38.18, 0.13908; 40.7253, 0.17211; 43.2707, 0.16686; 45.816, 0.15826; 48.3613, 0.14872; 50.9067, 0.15295; 53.452, 0.12677; 55.9973, 0.10964; 58.5427, 0.10223; 61.088, 0.10951; 63.6333, 0.088493; 66.1787, 0.068903; 68.724, 0.054396; 71.2693, 0.035731; 73.8147, 0.030172; 76.3, 0];
% Define initial guess values for parameters
lambda_init = 2.9;
kappa_init = 0.066;
theta_k_init = 0.45;
R_init = 2400;
rout = 76.3;
% Define c
c = sqrt(4 – (rout/R_init)^2);
% Define initial conditions as parameters
a0_bound = 0.0;
b0_bound = 0.0;
c0_bound = 0.0;
d0_bound = 0.0;
% Objective function
objective_function = @(params) compute_error(params, dr_data, dtheta_data, R_init, rout, c);
% Optimization options
options = optimoptions(@fminunc,’Display’,’iter’,’Algorithm’,’quasi-newton’,’MaxFunctionEvaluations’,10000,’MaxIterations’,10000);
% Perform optimization
best_params = fminunc(objective_function, [lambda_init, kappa_init, theta_k_init, a0_bound, b0_bound, c0_bound, d0_bound], options);
% Display best parameters
disp("Optimal Parameters:");
disp("Lambda: " + best_params(1));
disp("Kappa: " + best_params(2));
disp("Theta_k: " + best_params(3));
% Plot the results with the best parameters
[~, dr_fit, dtheta_fit] = compute_error(best_params, dr_data, dtheta_data, R_init, rout, c);
figure;
subplot(2,1,1);
plot(dr_data(:,1), dr_data(:,2), ‘ro’, dr_data(:,1), dr_fit, ‘b-‘);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Fit of dr(r) vs r’);
legend(‘Data’, ‘Fit’);
subplot(2,1,2);
plot(dtheta_data(:,1), dtheta_data(:,2), ‘ro’, dtheta_data(:,1), dtheta_fit, ‘b-‘);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Fit of dtheta(r) vs r’);
legend(‘Data’, ‘Fit’);
% Error computation function
function [error, dr_fit, dtheta_fit] = compute_error(params, dr_data, dtheta_data, R, rout, c)
lambda = params(1);
kappa = params(2);
theta_k = params(3);
a0 = params(4);
b0 = params(5);
c0 = params(6);
d0 = params(7);
% Define the function for the differential equations
f = @(r, y) [y(2); ((-1*(lambda+1)*(r*y(2)+y(1)))+(1/r)*((kappa*r^2*cos(theta_k)-(lambda+1))*y(1))-(kappa*r*y(3)*sin(theta_k))+(-16*lambda*r^2)/(c^4*R^2)); y(4); ((-1*(r*y(4)+y(3)))+(1/r)*((kappa*r^2*cos(theta_k)-1)*y(3))+(kappa*r*y(1)*sin(theta_k)))];
% Solve the differential equations using ode45
%r_span = [min(dr_data(:,1)), max(dr_data(:,1))]; % Span of r values from the data
r_span = dr_data(:,1);
[~, sol] = ode45(f, r_span, [a0, b0, c0, d0]);
% Extract solutions
dr_fit = sol(:,1);
dtheta_fit = sol(:,3);
% Compute error (sum of squared differences)
error_dr = sum((dr_data(:,2) – dr_fit).^2);
error_dtheta = sum((dtheta_data(:,2) – dtheta_fit).^2);
% Total error
error = error_dr + error_dtheta;
end
I want to fit the simulated d_r(r) vs r and d_theta(r) vs r values with the above mentioned coupled differential eqns by usuing the fitting parameters lamda, kappa, theta_k. For the sake of good fitting one can use boundary conditions as parameter also. However getting errors. Please help me to solve those errors and fitting those data.
The mathematical eqns and details are below:
$kappa>0$ and $0 leq theta_{k}<frac{pi}{2}$ describe the screening. The boundary conditions are $vec{d}(0)=vec{d}left(r_{text {out }}right)=(0,0)$.
For
$$
c=sqrt{4-left(frac{r_{text {out }}}{R}right)^{2}}
$$
Furthermore,
begin{equation}
(lambda+1)left(r d_{r}^{prime prime}(r)+d_{r}^{prime}(r)right) &+ frac{1}{r}left(kappa r^{2} cos theta_{k}-(lambda+1)right) d_{r}(r)\
& – kappa r d_{theta}(r) sin theta_{k} = -frac{16 lambda r^{2}}{c^{4} R^{2}}
end{equation}
begin{equation}
r d_{theta}^{prime prime}(r) + d_{theta}^{prime}(r) &+ frac{1}{r}left(kappa r^{2} cos theta_{k}-1right) d_{theta}(r)\
& + kappa r d_{r}(r) sin theta_{k} = 0
end{equation}% Define the data
dr_data = [2.5453, 0.042123; 5.0907, 0.075326; 7.636, 0.059506; 10.1813, 0.071553; 12.7267, 0.071365; 15.272, 0.067195; 17.8173, 0.046372; 20.3627, 0.043397; 22.908, 0.017179; 25.4533, -0.0063329; 27.9987, -0.030789; 30.544, -0.047569; 33.0893, -0.089512; 35.6347, -0.080675; 38.18, -0.089138; 40.7253, -0.1102; 43.2707, -0.12061; 45.816, -0.11857; 48.3613, -0.11955; 50.9067, -0.10803; 53.452, -0.10462; 55.9973, -0.099548; 58.5427, -0.097164; 61.088, -0.09994; 63.6333, -0.077017; 66.1787, -0.062839; 68.724, -0.048422; 71.2693, -0.03686; 73.8147, -0.01469; 76.3, 0];
dtheta_data = [2.5453, -0.099251; 5.0907, -0.16064; 7.636, -0.21858; 10.1813, -0.18965; 12.7267, -0.16996; 15.272, -0.18172; 17.8173, -0.15029; 20.3627, -0.12541; 22.908, -0.082786; 25.4533, -0.0071716; 27.9987, 0.03695; 30.544, 0.089002; 33.0893, 0.12873; 35.6347, 0.13092; 38.18, 0.13908; 40.7253, 0.17211; 43.2707, 0.16686; 45.816, 0.15826; 48.3613, 0.14872; 50.9067, 0.15295; 53.452, 0.12677; 55.9973, 0.10964; 58.5427, 0.10223; 61.088, 0.10951; 63.6333, 0.088493; 66.1787, 0.068903; 68.724, 0.054396; 71.2693, 0.035731; 73.8147, 0.030172; 76.3, 0];
% Define initial guess values for parameters
lambda_init = 2.9;
kappa_init = 0.066;
theta_k_init = 0.45;
R_init = 2400;
rout = 76.3;
% Define c
c = sqrt(4 – (rout/R_init)^2);
% Define initial conditions as parameters
a0_bound = 0.0;
b0_bound = 0.0;
c0_bound = 0.0;
d0_bound = 0.0;
% Objective function
objective_function = @(params) compute_error(params, dr_data, dtheta_data, R_init, rout, c);
% Optimization options
options = optimoptions(@fminunc,’Display’,’iter’,’Algorithm’,’quasi-newton’,’MaxFunctionEvaluations’,10000,’MaxIterations’,10000);
% Perform optimization
best_params = fminunc(objective_function, [lambda_init, kappa_init, theta_k_init, a0_bound, b0_bound, c0_bound, d0_bound], options);
% Display best parameters
disp("Optimal Parameters:");
disp("Lambda: " + best_params(1));
disp("Kappa: " + best_params(2));
disp("Theta_k: " + best_params(3));
% Plot the results with the best parameters
[~, dr_fit, dtheta_fit] = compute_error(best_params, dr_data, dtheta_data, R_init, rout, c);
figure;
subplot(2,1,1);
plot(dr_data(:,1), dr_data(:,2), ‘ro’, dr_data(:,1), dr_fit, ‘b-‘);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Fit of dr(r) vs r’);
legend(‘Data’, ‘Fit’);
subplot(2,1,2);
plot(dtheta_data(:,1), dtheta_data(:,2), ‘ro’, dtheta_data(:,1), dtheta_fit, ‘b-‘);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Fit of dtheta(r) vs r’);
legend(‘Data’, ‘Fit’);
% Error computation function
function [error, dr_fit, dtheta_fit] = compute_error(params, dr_data, dtheta_data, R, rout, c)
lambda = params(1);
kappa = params(2);
theta_k = params(3);
a0 = params(4);
b0 = params(5);
c0 = params(6);
d0 = params(7);
% Define the function for the differential equations
f = @(r, y) [y(2); ((-1*(lambda+1)*(r*y(2)+y(1)))+(1/r)*((kappa*r^2*cos(theta_k)-(lambda+1))*y(1))-(kappa*r*y(3)*sin(theta_k))+(-16*lambda*r^2)/(c^4*R^2)); y(4); ((-1*(r*y(4)+y(3)))+(1/r)*((kappa*r^2*cos(theta_k)-1)*y(3))+(kappa*r*y(1)*sin(theta_k)))];
% Solve the differential equations using ode45
%r_span = [min(dr_data(:,1)), max(dr_data(:,1))]; % Span of r values from the data
r_span = dr_data(:,1);
[~, sol] = ode45(f, r_span, [a0, b0, c0, d0]);
% Extract solutions
dr_fit = sol(:,1);
dtheta_fit = sol(:,3);
% Compute error (sum of squared differences)
error_dr = sum((dr_data(:,2) – dr_fit).^2);
error_dtheta = sum((dtheta_data(:,2) – dtheta_fit).^2);
% Total error
error = error_dr + error_dtheta;
end
I want to fit the simulated d_r(r) vs r and d_theta(r) vs r values with the above mentioned coupled differential eqns by usuing the fitting parameters lamda, kappa, theta_k. For the sake of good fitting one can use boundary conditions as parameter also. However getting errors. Please help me to solve those errors and fitting those data.
The mathematical eqns and details are below:
$kappa>0$ and $0 leq theta_{k}<frac{pi}{2}$ describe the screening. The boundary conditions are $vec{d}(0)=vec{d}left(r_{text {out }}right)=(0,0)$.
For
$$
c=sqrt{4-left(frac{r_{text {out }}}{R}right)^{2}}
$$
Furthermore,
begin{equation}
(lambda+1)left(r d_{r}^{prime prime}(r)+d_{r}^{prime}(r)right) &+ frac{1}{r}left(kappa r^{2} cos theta_{k}-(lambda+1)right) d_{r}(r)\
& – kappa r d_{theta}(r) sin theta_{k} = -frac{16 lambda r^{2}}{c^{4} R^{2}}
end{equation}
begin{equation}
r d_{theta}^{prime prime}(r) + d_{theta}^{prime}(r) &+ frac{1}{r}left(kappa r^{2} cos theta_{k}-1right) d_{theta}(r)\
& + kappa r d_{r}(r) sin theta_{k} = 0
end{equation} % Define the data
dr_data = [2.5453, 0.042123; 5.0907, 0.075326; 7.636, 0.059506; 10.1813, 0.071553; 12.7267, 0.071365; 15.272, 0.067195; 17.8173, 0.046372; 20.3627, 0.043397; 22.908, 0.017179; 25.4533, -0.0063329; 27.9987, -0.030789; 30.544, -0.047569; 33.0893, -0.089512; 35.6347, -0.080675; 38.18, -0.089138; 40.7253, -0.1102; 43.2707, -0.12061; 45.816, -0.11857; 48.3613, -0.11955; 50.9067, -0.10803; 53.452, -0.10462; 55.9973, -0.099548; 58.5427, -0.097164; 61.088, -0.09994; 63.6333, -0.077017; 66.1787, -0.062839; 68.724, -0.048422; 71.2693, -0.03686; 73.8147, -0.01469; 76.3, 0];
dtheta_data = [2.5453, -0.099251; 5.0907, -0.16064; 7.636, -0.21858; 10.1813, -0.18965; 12.7267, -0.16996; 15.272, -0.18172; 17.8173, -0.15029; 20.3627, -0.12541; 22.908, -0.082786; 25.4533, -0.0071716; 27.9987, 0.03695; 30.544, 0.089002; 33.0893, 0.12873; 35.6347, 0.13092; 38.18, 0.13908; 40.7253, 0.17211; 43.2707, 0.16686; 45.816, 0.15826; 48.3613, 0.14872; 50.9067, 0.15295; 53.452, 0.12677; 55.9973, 0.10964; 58.5427, 0.10223; 61.088, 0.10951; 63.6333, 0.088493; 66.1787, 0.068903; 68.724, 0.054396; 71.2693, 0.035731; 73.8147, 0.030172; 76.3, 0];
% Define initial guess values for parameters
lambda_init = 2.9;
kappa_init = 0.066;
theta_k_init = 0.45;
R_init = 2400;
rout = 76.3;
% Define c
c = sqrt(4 – (rout/R_init)^2);
% Define initial conditions as parameters
a0_bound = 0.0;
b0_bound = 0.0;
c0_bound = 0.0;
d0_bound = 0.0;
% Objective function
objective_function = @(params) compute_error(params, dr_data, dtheta_data, R_init, rout, c);
% Optimization options
options = optimoptions(@fminunc,’Display’,’iter’,’Algorithm’,’quasi-newton’,’MaxFunctionEvaluations’,10000,’MaxIterations’,10000);
% Perform optimization
best_params = fminunc(objective_function, [lambda_init, kappa_init, theta_k_init, a0_bound, b0_bound, c0_bound, d0_bound], options);
% Display best parameters
disp("Optimal Parameters:");
disp("Lambda: " + best_params(1));
disp("Kappa: " + best_params(2));
disp("Theta_k: " + best_params(3));
% Plot the results with the best parameters
[~, dr_fit, dtheta_fit] = compute_error(best_params, dr_data, dtheta_data, R_init, rout, c);
figure;
subplot(2,1,1);
plot(dr_data(:,1), dr_data(:,2), ‘ro’, dr_data(:,1), dr_fit, ‘b-‘);
xlabel(‘r’);
ylabel(‘dr(r)’);
title(‘Fit of dr(r) vs r’);
legend(‘Data’, ‘Fit’);
subplot(2,1,2);
plot(dtheta_data(:,1), dtheta_data(:,2), ‘ro’, dtheta_data(:,1), dtheta_fit, ‘b-‘);
xlabel(‘r’);
ylabel(‘dtheta(r)’);
title(‘Fit of dtheta(r) vs r’);
legend(‘Data’, ‘Fit’);
% Error computation function
function [error, dr_fit, dtheta_fit] = compute_error(params, dr_data, dtheta_data, R, rout, c)
lambda = params(1);
kappa = params(2);
theta_k = params(3);
a0 = params(4);
b0 = params(5);
c0 = params(6);
d0 = params(7);
% Define the function for the differential equations
f = @(r, y) [y(2); ((-1*(lambda+1)*(r*y(2)+y(1)))+(1/r)*((kappa*r^2*cos(theta_k)-(lambda+1))*y(1))-(kappa*r*y(3)*sin(theta_k))+(-16*lambda*r^2)/(c^4*R^2)); y(4); ((-1*(r*y(4)+y(3)))+(1/r)*((kappa*r^2*cos(theta_k)-1)*y(3))+(kappa*r*y(1)*sin(theta_k)))];
% Solve the differential equations using ode45
%r_span = [min(dr_data(:,1)), max(dr_data(:,1))]; % Span of r values from the data
r_span = dr_data(:,1);
[~, sol] = ode45(f, r_span, [a0, b0, c0, d0]);
% Extract solutions
dr_fit = sol(:,1);
dtheta_fit = sol(:,3);
% Compute error (sum of squared differences)
error_dr = sum((dr_data(:,2) – dr_fit).^2);
error_dtheta = sum((dtheta_data(:,2) – dtheta_fit).^2);
% Total error
error = error_dr + error_dtheta;
end
I want to fit the simulated d_r(r) vs r and d_theta(r) vs r values with the above mentioned coupled differential eqns by usuing the fitting parameters lamda, kappa, theta_k. For the sake of good fitting one can use boundary conditions as parameter also. However getting errors. Please help me to solve those errors and fitting those data.
The mathematical eqns and details are below:
$kappa>0$ and $0 leq theta_{k}<frac{pi}{2}$ describe the screening. The boundary conditions are $vec{d}(0)=vec{d}left(r_{text {out }}right)=(0,0)$.
For
$$
c=sqrt{4-left(frac{r_{text {out }}}{R}right)^{2}}
$$
Furthermore,
begin{equation}
(lambda+1)left(r d_{r}^{prime prime}(r)+d_{r}^{prime}(r)right) &+ frac{1}{r}left(kappa r^{2} cos theta_{k}-(lambda+1)right) d_{r}(r)\
& – kappa r d_{theta}(r) sin theta_{k} = -frac{16 lambda r^{2}}{c^{4} R^{2}}
end{equation}
begin{equation}
r d_{theta}^{prime prime}(r) + d_{theta}^{prime}(r) &+ frac{1}{r}left(kappa r^{2} cos theta_{k}-1right) d_{theta}(r)\
& + kappa r d_{r}(r) sin theta_{k} = 0
end{equation} curve fitting, parametes, solve eqns MATLAB Answers — New Questions
Maximum recursion limit of 500 reached. Use set(0,’RecursionLimit’,N) to change the limit. Be aware that exceeding your available stack space can crash MATLAB and/or your computer.
it’s fine working on another laptop but in my laptop will getting above error………? can any one solve this….?
clear all;
close all;
a=imread(‘indus.jpg’);
b=rgb2gray(a);
[m,n]=size(b);
r=im2double(b);
% r=im2bw(b,0.75);
% ^r=b;
out=r;
for i=2:m-1
for j=2:n-1
h=[1*r(i-1,j-1) 1*r(i-1,j) 1*r(i-1,j+1);…
1*r(i,j-1) 1*r(i,j) 1*r(i,j+1);…
1*r(i+1,j-1) 1*r(i+1,j) 1*r(i+1,j+1)];
out(i,j)=(median(median(h)));
end
end
r=out;
sobel=r;
for i=2:m-1
for j=2:n-1
h=[-1*r(i-1,j-1) 0*r(i-1,j) 1*r(i-1,j+1);…
-2*r(i,j-1) 0*r(i,j) 2*r(i,j+1);…
-1*r(i+1,j-1) 0*r(i+1,j) 1*r(i+1,j+1)];
sobel(i,j)=(mean(mean(h)));
end
end
sobel1=sobel;
for i=2:m-1
for j=2:n-1
h=[-1*sobel(i-1,j-1) -2*sobel(i-1,j) -1*sobel(i-1,j+1);…
0*sobel(i,j-1) 0*sobel(i,j) 0*sobel(i,j+1);…
1*sobel(i+1,j-1) 2*sobel(i+1,j) 1*sobel(i+1,j+1)];
sobel1(i,j)=(mean(mean(h)));
end
end
% a=min(r,sobel1);
% figure,imshow(a);
res=max(sobel1,r);
figure,imshow(res);
subplot(221);imshow(r,[]);
subplot(222);imshow(res,[]);
subplot(223);imshow(sobel,[]);
subplot(224);imshow(sobel1,[]);it’s fine working on another laptop but in my laptop will getting above error………? can any one solve this….?
clear all;
close all;
a=imread(‘indus.jpg’);
b=rgb2gray(a);
[m,n]=size(b);
r=im2double(b);
% r=im2bw(b,0.75);
% ^r=b;
out=r;
for i=2:m-1
for j=2:n-1
h=[1*r(i-1,j-1) 1*r(i-1,j) 1*r(i-1,j+1);…
1*r(i,j-1) 1*r(i,j) 1*r(i,j+1);…
1*r(i+1,j-1) 1*r(i+1,j) 1*r(i+1,j+1)];
out(i,j)=(median(median(h)));
end
end
r=out;
sobel=r;
for i=2:m-1
for j=2:n-1
h=[-1*r(i-1,j-1) 0*r(i-1,j) 1*r(i-1,j+1);…
-2*r(i,j-1) 0*r(i,j) 2*r(i,j+1);…
-1*r(i+1,j-1) 0*r(i+1,j) 1*r(i+1,j+1)];
sobel(i,j)=(mean(mean(h)));
end
end
sobel1=sobel;
for i=2:m-1
for j=2:n-1
h=[-1*sobel(i-1,j-1) -2*sobel(i-1,j) -1*sobel(i-1,j+1);…
0*sobel(i,j-1) 0*sobel(i,j) 0*sobel(i,j+1);…
1*sobel(i+1,j-1) 2*sobel(i+1,j) 1*sobel(i+1,j+1)];
sobel1(i,j)=(mean(mean(h)));
end
end
% a=min(r,sobel1);
% figure,imshow(a);
res=max(sobel1,r);
figure,imshow(res);
subplot(221);imshow(r,[]);
subplot(222);imshow(res,[]);
subplot(223);imshow(sobel,[]);
subplot(224);imshow(sobel1,[]); it’s fine working on another laptop but in my laptop will getting above error………? can any one solve this….?
clear all;
close all;
a=imread(‘indus.jpg’);
b=rgb2gray(a);
[m,n]=size(b);
r=im2double(b);
% r=im2bw(b,0.75);
% ^r=b;
out=r;
for i=2:m-1
for j=2:n-1
h=[1*r(i-1,j-1) 1*r(i-1,j) 1*r(i-1,j+1);…
1*r(i,j-1) 1*r(i,j) 1*r(i,j+1);…
1*r(i+1,j-1) 1*r(i+1,j) 1*r(i+1,j+1)];
out(i,j)=(median(median(h)));
end
end
r=out;
sobel=r;
for i=2:m-1
for j=2:n-1
h=[-1*r(i-1,j-1) 0*r(i-1,j) 1*r(i-1,j+1);…
-2*r(i,j-1) 0*r(i,j) 2*r(i,j+1);…
-1*r(i+1,j-1) 0*r(i+1,j) 1*r(i+1,j+1)];
sobel(i,j)=(mean(mean(h)));
end
end
sobel1=sobel;
for i=2:m-1
for j=2:n-1
h=[-1*sobel(i-1,j-1) -2*sobel(i-1,j) -1*sobel(i-1,j+1);…
0*sobel(i,j-1) 0*sobel(i,j) 0*sobel(i,j+1);…
1*sobel(i+1,j-1) 2*sobel(i+1,j) 1*sobel(i+1,j+1)];
sobel1(i,j)=(mean(mean(h)));
end
end
% a=min(r,sobel1);
% figure,imshow(a);
res=max(sobel1,r);
figure,imshow(res);
subplot(221);imshow(r,[]);
subplot(222);imshow(res,[]);
subplot(223);imshow(sobel,[]);
subplot(224);imshow(sobel1,[]); maximum recursion limit of 500 reached. use set(0, ‘recursionlimit’, n) MATLAB Answers — New Questions