Month: July 2024
f = x^2024. Write a loop to find how many times f needs to be differentiated to get a result of zero.
A sequence of functions F0, F1, F2…is defined as follows, for x a positive real number:#
F0 = x^2024
For n>=1, the function Fn is the derivative of F(n-1), with respect to x.
Find the first value of n for which Fn = 0A sequence of functions F0, F1, F2…is defined as follows, for x a positive real number:#
F0 = x^2024
For n>=1, the function Fn is the derivative of F(n-1), with respect to x.
Find the first value of n for which Fn = 0 A sequence of functions F0, F1, F2…is defined as follows, for x a positive real number:#
F0 = x^2024
For n>=1, the function Fn is the derivative of F(n-1), with respect to x.
Find the first value of n for which Fn = 0 loops, differentiation MATLAB Answers — New Questions
Rename the indices of a vector in a certain way.
Hi all,
My code below has a vector and its index vector . It goes throguh the elements of and when it finds a zero element, it removes its index from the orginal index vector.
My problem here is: suppose the updated index vector is . How can I rename this vector so it increases in an acending order? For example: the first element in the updated index vector is , I want this to be , the second element in the updated index vector is , I want this to become , and so on so forth.
%define the index vector
idx = [1 2 3 4 5];
%define the vector
A = [5 0 6 0 3];
%initialise the vector that has all indices of zero elements
zero_indices = [];
%go through the elements of vector A
for uu = 1:numel(A)
%if the element is zero
if A(uu)==0
%assign its index to the zero-elements index vector
zeroindex = uu;
%collect all results from iterations
zero_indices = [zero_indices ; zeroindex];
end
end
%update the original index vector by removing the indicies that correspond
%to zero elements
idx(zero_indices) = [];
%rename the indices os that they beocome 1, 2, 3, …
Any help would be appreicted.
Thanks.Hi all,
My code below has a vector and its index vector . It goes throguh the elements of and when it finds a zero element, it removes its index from the orginal index vector.
My problem here is: suppose the updated index vector is . How can I rename this vector so it increases in an acending order? For example: the first element in the updated index vector is , I want this to be , the second element in the updated index vector is , I want this to become , and so on so forth.
%define the index vector
idx = [1 2 3 4 5];
%define the vector
A = [5 0 6 0 3];
%initialise the vector that has all indices of zero elements
zero_indices = [];
%go through the elements of vector A
for uu = 1:numel(A)
%if the element is zero
if A(uu)==0
%assign its index to the zero-elements index vector
zeroindex = uu;
%collect all results from iterations
zero_indices = [zero_indices ; zeroindex];
end
end
%update the original index vector by removing the indicies that correspond
%to zero elements
idx(zero_indices) = [];
%rename the indices os that they beocome 1, 2, 3, …
Any help would be appreicted.
Thanks. Hi all,
My code below has a vector and its index vector . It goes throguh the elements of and when it finds a zero element, it removes its index from the orginal index vector.
My problem here is: suppose the updated index vector is . How can I rename this vector so it increases in an acending order? For example: the first element in the updated index vector is , I want this to be , the second element in the updated index vector is , I want this to become , and so on so forth.
%define the index vector
idx = [1 2 3 4 5];
%define the vector
A = [5 0 6 0 3];
%initialise the vector that has all indices of zero elements
zero_indices = [];
%go through the elements of vector A
for uu = 1:numel(A)
%if the element is zero
if A(uu)==0
%assign its index to the zero-elements index vector
zeroindex = uu;
%collect all results from iterations
zero_indices = [zero_indices ; zeroindex];
end
end
%update the original index vector by removing the indicies that correspond
%to zero elements
idx(zero_indices) = [];
%rename the indices os that they beocome 1, 2, 3, …
Any help would be appreicted.
Thanks. index, matlab coder, vector, while loop, remove, delete MATLAB Answers — New Questions
How can I change the axis intervals using powers?
Hi.
I recently was trying to make a scientific graph, which required the X Axis to be in even intervals of powers of 10 (i.e. 0.1, 10, 100, 1000, etc.) with no in-betweeners. When I tried to use the xtick function, the command worked, but it didn’t create the necessary even spacing required at the intervals. What can I do? (The code and images are below.)
size = particle_size.("Size (d.nm)");
number = particle_size.("Number (Percent)");
plot(normalize(size,’range’,[0.1 10000]),number,"red",LineWidth=0.5)
xlim([0.1 10000])
ylim([0 14])
title("Particle Size Of Carbon Leaves",FontSize=20,FontWeight="bold")
xlabel("Size (d.nm)",FontSize=14,FontWeight="bold")
ylabel("Number (Percent)",FontSize=14,FontWeight="bold")
legend("Carbon Leaves",FontWeight="bold")
xtick = [0.1, 1, 10, 100, 1000, 10000];
box on
ax = gca;
ax.LineWidth = 2;
ax.FontSize = 12;
ax.XTick = xtick;
(The graph required)
(What MATLAB gave me)Hi.
I recently was trying to make a scientific graph, which required the X Axis to be in even intervals of powers of 10 (i.e. 0.1, 10, 100, 1000, etc.) with no in-betweeners. When I tried to use the xtick function, the command worked, but it didn’t create the necessary even spacing required at the intervals. What can I do? (The code and images are below.)
size = particle_size.("Size (d.nm)");
number = particle_size.("Number (Percent)");
plot(normalize(size,’range’,[0.1 10000]),number,"red",LineWidth=0.5)
xlim([0.1 10000])
ylim([0 14])
title("Particle Size Of Carbon Leaves",FontSize=20,FontWeight="bold")
xlabel("Size (d.nm)",FontSize=14,FontWeight="bold")
ylabel("Number (Percent)",FontSize=14,FontWeight="bold")
legend("Carbon Leaves",FontWeight="bold")
xtick = [0.1, 1, 10, 100, 1000, 10000];
box on
ax = gca;
ax.LineWidth = 2;
ax.FontSize = 12;
ax.XTick = xtick;
(The graph required)
(What MATLAB gave me) Hi.
I recently was trying to make a scientific graph, which required the X Axis to be in even intervals of powers of 10 (i.e. 0.1, 10, 100, 1000, etc.) with no in-betweeners. When I tried to use the xtick function, the command worked, but it didn’t create the necessary even spacing required at the intervals. What can I do? (The code and images are below.)
size = particle_size.("Size (d.nm)");
number = particle_size.("Number (Percent)");
plot(normalize(size,’range’,[0.1 10000]),number,"red",LineWidth=0.5)
xlim([0.1 10000])
ylim([0 14])
title("Particle Size Of Carbon Leaves",FontSize=20,FontWeight="bold")
xlabel("Size (d.nm)",FontSize=14,FontWeight="bold")
ylabel("Number (Percent)",FontSize=14,FontWeight="bold")
legend("Carbon Leaves",FontWeight="bold")
xtick = [0.1, 1, 10, 100, 1000, 10000];
box on
ax = gca;
ax.LineWidth = 2;
ax.FontSize = 12;
ax.XTick = xtick;
(The graph required)
(What MATLAB gave me) graphs, axis MATLAB Answers — New Questions
What do you think about RSVP in Outlook?
Hello Calendar Community,
RSVP (responding to meeting invitations) is an area with lots of opportunity for improvements in Outlook Calendar. I’m reaching out to gather your feedback on RSVP.
We’re particularly interested in understanding:
Ease of Use: How intuitive and user-friendly do you find the current RSVP process?
Functionality: Are there any features you wish were included to improve the RSVP experience?
Efficiency: How could we make RSVPing quicker and more efficient for you?
Overall Experience: Any other comments on your overall experience with the RSVP functionality?
Feel free to share your thoughts in the comments. I am really eager for some insights from our community and its power calendar users.
cheers,
Gio
Hello Calendar Community,
RSVP (responding to meeting invitations) is an area with lots of opportunity for improvements in Outlook Calendar. I’m reaching out to gather your feedback on RSVP.
We’re particularly interested in understanding:
Ease of Use: How intuitive and user-friendly do you find the current RSVP process?
Functionality: Are there any features you wish were included to improve the RSVP experience?
Efficiency: How could we make RSVPing quicker and more efficient for you?
Overall Experience: Any other comments on your overall experience with the RSVP functionality?
Feel free to share your thoughts in the comments. I am really eager for some insights from our community and its power calendar users.
cheers,
Gio Read More
Visual Studio AI Toolkit : Building Phi-3 GenAI Applications
Level up your Generative AI development with Microsoft’s AI Toolkit! In the previous blog, we explored how AI Toolkit empowers you to run LLMs/SLMs locally.
AI toolkit lets us to,
Run pre-optimized AI models locally: Get started quickly with models designed for various setups, including Windows 11 running with DirectML acceleration or direct CPU, Linux with NVIDIA GPUs, or CPU-only environments.
Test and integrate models seamlessly: Experiment with models in a user-friendly playground or use a REST API to incorporate them directly into your application.
Fine-tune models for specific needs: Customize pre-trained models (like popular SLMs Phi-3 and Mistral) locally or in the cloud to enhance performance, tailor responses, and control their style.
Deploy your AI-powered features: Choose between cloud deployment or embedding them within your device applications.
Port Forwarding, a valuable feature within the AI Toolkit, serves as a crucial gateway for seamless communication with the GenAI model. Whether it’s through a straightforward API call or leveraging the SDKs, this functionality greatly enhances our ability to harness the power of the LLM/SLM. By enabling Port Forwarding, a plethora of new scenarios unfold, unlocking the full potential of our interactions with the model.
Port forwarding is like setting up a special path for data to travel between two devices over the internet. In the context of AI Toolkit, port forwarding involves configuring a pathway for communication between the LLM and external applications or systems, enabling seamless data exchange and interaction.
AI toolkit auto forwards the port to 5272 by default. If needed this can be modified or new ports can be added. This can be seen the moment we load the AI Toolkit extension on VS Code. A notification can be seen on the right side of the screen stating the “Your application running on port 5272 is available”
The 5272 is default port assigned by AI Toolkit, if we wish to add more ports, that can be done by navigating to the PORTS terminal on VS Code and then clicking on the “Add Ports” button.
In this, we can see the section “Forwarded address”. This is the address which will be used for communicating with the SLM. For this tutorial, Phi-3 will be used. This is a Small Language Model from Microsoft. It can be downloaded from the Model Catalog section.
Testing and comprehending the API Endpoint on POSTMAN:
Testing out an application from the API testing application, gives a clear knowledge about the API specification. This can also be done using the coding language, but for this demonstration, I will be showcasing it through the POSTMAN application. Postman application needs to be downloaded and installed on the local machine. Also sign up and create an account if you don’t have one. Once the application is launched, click on create a new request, it will be displayed as “+’” icon.
In order to do this testing, we would need some basic information about the API that we are testing. Details like Request method, Request URL, request body, type of the request body, authentication type are some of the mandatory things which will be needed. For the Visual Studio Code AI Toolkit API with Phi-3-mini-128k-cuda-int4-onnx model, the details are as follows,
Authentication: None
Request method: POST
Request URL:
http://127.0.0.1:5272/v1/chat/completions
Request Body type: Raw/JSON
Request Body:
{
“model”: “Phi-3-mini-128k-cuda-int4-onnx”,
“messages”: [
{
“role”: “user”,
“content”: “Hi”
}
],
“temperature”: 0.7,
“top_p”: 1,
“top_k”: 10,
“max_tokens”: 100,
“stream”: false
}
Authentication will be defaulting to None. So, it can be retained here to None as it is. HTTP request method here would be POST. The Request URL must be checked according to the Port that has been assigned, if it is the default port which is assigned by the visual studio ai toolkit, it will be 5272. Incase, it is changed to any other port, it must be changed in the URL as well. This will be a HTTP request and the URL must contain the URL address, followed by the port and the routes must be set as shown above.
The “model” parameter in the request body must have the same model that is being loaded in the VS Code AI Toolkit – playground section.
Request body type must be set to Raw and from the dropdown, select JSON.
The streaming parameter must be set to false, else the response will be streamed and divided into sub-classes of JSON which is hard to comprehend. In-case if the application needs streaming, then the parameter can be set to TRUE.
Once these are ready, use the Send button and wait for the response. If the API call is successful, 200 OK will be displayed and a response body will be visible in the Body tab.
NOTE: The VS Code AI Toolkit must be running in the background, and load the model in the playground before sending the API response in Postman.
The response of the above request is as follows,
Meanwhile, this will also be reflected on the VS Code AI toolkit Output window as well.
The response body carries quite a lot of information, the answer that will be used in the application is in the “content” division. The code must navigate to the first section of the choices then the messages and finally to the content section. In python, it can be done by,
chat_completion.choices[0].messages.content
This will be further used while building the playground application in the later part of this tutorial.
The response body also provides some more useful information like the ID, created stamp, finish reason to name a few. The role parameter shows that the response is from the model and hence shows “assistant”.
Code snippet can also be generated with the POSTMAN app, which can be then used for testing the API. Following is the example for the Python Code using the HTTP Client.
Using the VS Code AI Toolkit with Python:
from openai import OpenAI
client = OpenAI(
base_url=”http://127.0.0.1:5272/v1/”,
api_key=”xyz” # required by API but not used
)
chat_completion = client.chat.completions.create(
messages=[
{
“role”: “user”,”content”: “What is the capital of India?””,
}
],
model=”Phi-3-mini-128k-cuda-int4-onnx”,
)
print(chat_completion.choices[0].message.content)
The Python script interacts with an API (local instance of OpenAI’s API) to get a chat completion.
Step-by-step explanation of Python Implementation:
Importing the OpenAI library: The script starts by importing the OpenAI class from the openai package. This class is used to interact with OpenAI’s API. It can be installed using the simple python command as follows.
pip install openai
Although we are not communicating to the OpenAI’s API, we are utilizing the OS library to interact with the model running in local machine.
Create an OpenAI client instance: Initialize an OpenAI client with a base URL pointing to http://127.0.0.1:5272/v1/, which suggests the API is hosted locally rather than on OpenAI’s cloud servers. An API key, “XYZ”, is also provided, which is noted as required by the API but not used in this context. The API key can be set to anything and not necessarily XYZ.
Create a chat completion request: The script then creates a chat completion request using the chat.completions.create method of the client. This method is called with two parameters:
messages: A list containing a single message dictionary where the role is set to “user” and the content is the question ” What is the capital of India?”. This structure mimics a chat interaction where a user asks a question.
model: Specifies the model to use for generating the completion, in this case, “Phi-3-mini-128k-cuda-int4-onnx”. This indicates a specific model configuration.
Print the response: Finally, the script prints the content of the first message from the response’s choices. API returns a list of possible completions (choices), and it accesses the content of the message from the first choice to display the answer to the user’s question as demonstrated in the POSTMAN section.
Run the code in a new VS Code window. Preferably use a virtual environment to execute this code. Python is a prerequisite. To learn more, click here.
Execute the code using, the command
python <filename>.py #replace filename with the respective filename.
or click on the run button on the top right side of the Visual Studio Code window.
The response is now printed on the terminal.
Developing Basic Application:
Similarly, we can use it in applications as well. To demonstrate, lets build a basic application using Streamlit and python. Streamlit turns python scripts into shareable web apps in minutes. To know more click here. To install streamlit, use the following command in the python terminal/VS Code terminal.
pip install streamlit
The following script creates a web-based chat interface using streamlit where users can input queries, which are then sent to an AI model via a local OpenAI API server. The AI’s responses are displayed back in the chat interface, facilitating a conversational interaction.
import streamlit as st
from openai import OpenAI
client = OpenAI(
base_url=”http://127.0.0.1:5272/v1/”,
api_key=”xyz” # required by API but not used
)
st.title(“Chat with Phi-3”)
query = st.chat_input(“Enter query:”)
if query:
with st.chat_message(“user”):
st.write(query)
chat_completion = client.chat.completions.create(
messages=[
{“role”: “user”,”content”: “You are a helpful assistant and provides structured answers.”},
{“role”: “user”, “content”: query}
],
model=”Phi-3-mini-128k-cuda-int4-onnx”,
)
with st.chat_message(“assistant”):
st.write(chat_completion.choices[0].message.content)
Since the above code is using the streamlit, the startup command is also given in a different syntax, the command is as follows,
streamlit run <filename>.py #replace filename with the respective filename.
Upon successful execution, the streamlit pops up a new window in the Microsoft edge with the webpage.
This is how we can create GenAI applications by using the models running on local VS Code AI Toolkit environment. In the upcoming blog, lets see how to apply retrieval augmented generation using the AI Toolkit framework.
Microsoft Tech Community – Latest Blogs –Read More
Contact angle measurements for droplets with a capillary
Hello everyone
My name is Baraa, I recently started using Matlab (Bigginner), and I need your help in explaining the error I keep making in the following code. The code is supposed to measure the contact angle of a droplet based on defining the edges of the droplet, masking the capillary, dividing the pixels on the edges of the droplet by 2 (so we can have left and right), finding the reflection of each side to define the contact points between the surface and the droplet on each side, and finally connecting the contact points together. The code then fits the pixels to find the tangent and calculates the contact angle between the tangent and the line between the contact points.
The main problem is that the code doesn’t work with all droplets and most of the time I have errors with droplets with high wettability and high volume (the droplets spread on the surface). The error message is as follows:
Index in position 1 exceeds array bounds. Index must not exceed 1113.
Error in findreflection (line 50)
x2=trace(index+n2:index+n-1,2);
Error in contactAngleImageAnalysis (line 104)
[x0L,y0L,indexL]=findreflection([edgeL.x,edgeL.y],70,0); % change the last entry (160) to zero and see what happens
How can I modify the code to make it suitable for any droplet volume?
P.S
The code always fails to read this image (Co-Eth-1, see attached) and it reads probably reads this image (Co-Eth-1b, see attached). Please refer to the two images.
Thank you very much in advance
clc
clear all
close all
addpath(genpath("C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopcodesContact Angle FittingScriptsSubpixel Matlab v2.11"));
addpath(genpath("C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopcodesContact Angle FittingScripts"));
main_path = "C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopIMAGES25.06.24";
output_folder = "C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopsessileDrop_processed";
%these are the coordinates of the polygon to mask the cannula
Xright=3100;%this the X value on the right side of the ploygon and it represents top and bottom if the right side of the polygon.
Xleft=2800;%this is the X value of the left side of the ploygon and it represents both top and bottom x cordinates
Y_top=0;% this is the y value on the top side of the polygon for both left and right side
Y_bottom=2050;% this is the y value of the bottom side of the ploygon for both left and right side
%******************************pixel intensity***************************
pixelValue=255;
%***********************threshold to be used*****************************
trsh_sub=4;
% Read a group of images from a folder
imageFiles = dir(fullfile(main_path, ‘*.png’)); % Assuming images are in PNG format
numImages = input(‘Enter the number of images to work with: ‘);
% Create cell arrays to store data
imageNumbers = zeros(numImages, 1);
CAL_values = zeros(numImages, 1);
CAR_values = zeros(numImages, 1);
for k = 1:numImages
% Load image
filename = imageFiles(k).name;
im_load = fullfile(main_path, filename);
im = imread(im_load);
%—————————————————————–
% Masking the cannula
%—————————————————————–
% Define the coordinates of the four points
maskSize = size(im);
pointCoordinates = [Xleft, Y_bottom; Xright, Y_bottom; Xright, Y_top; Xleft, Y_top];
mask = zeros(maskSize(1), maskSize(2));
mask = poly2mask(pointCoordinates(:, 1), pointCoordinates(:, 2), maskSize(1), maskSize(2));
burnedImage = im;
burnedImage(mask) = pixelValue;
%—————————————————————
% Step 2 Detect boundaries in image
%—————————————————————
[edges, RI] = subpixelEdges(burnedImage, trsh_sub);
im_size=size(burnedImage);
im_size=size(burnedImage);
points = detectHarrisFeatures(burnedImage);
strongest = selectStrongest(points,10);
f2h=figure;
imshow(burnedImage)
hold on
plot(edges.x,edges.y,’r.’,’LineWidth’,2)
% plot(edges.x(1), edges.y(1),’b*’)
% plot(edges.x(im_size(1)),edges.y(im_size(2)),’g*’)
plot(strongest)
set(f2h,’Units’,’normalized’,’Position’,[0.31,0.6,0.3,0.3])
%—————————————————————
% Step 3 Select longes boundary in image
%—————————————————————
longestedge=findlongestedge(edges,size(burnedImage),5);
f3h=figure;
imshow(burnedImage)
hold on
plot(longestedge.x,longestedge.y,’r.’,’LineWidth’,2)
set(f3h,’Units’,’normalized’,’Position’,[0.62,0.6,0.3,0.3])
%—————————————————————
% Step 4 Split edge into left and right and sort it
%—————————————————————
[edgeL,edgeR]=leftrightedges(longestedge);
f4h=figure;
imshow(burnedImage)
hold on
plot(edgeL.x,edgeL.y,’r’,’LineWidth’,2)
plot(edgeR.x,edgeR.y,’b’,’LineWidth’,2)
set(f4h,’Units’,’normalized’,’Position’,[0.0,0.3,0.3,0.3])
%—————————————————————
% Step 5 Find reflection
%—————————————————————
[x0L,y0L,indexL]=findreflection([edgeL.x,edgeL.y],70,0); % change the last entry (160) to zero and see what happens
[x0R,y0R,indexR]=findreflection([edgeR.x,edgeR.y],60,0);
f5h=figure;
imshow(burnedImage)
hold on
plot(edgeL.x,edgeL.y,’r’,’LineWidth’,2)
plot(edgeR.x,edgeR.y,’b’,’LineWidth’,2)
plot(x0L,y0L,’yx’,’MarkerSize’,10,’LineWidth’,2)
plot(x0R,y0R,’yx’,’MarkerSize’,10,’LineWidth’,2)
t=linspace(-3,3);
plot((x0L-x0R)*t+x0R,(y0L-y0R)*t+y0R,’r–‘,’LineWidth’,2)
set(f5h,’Units’,’normalized’,’Position’,[0.31,0.3,0.3,0.3])
%—————————————————————
% Step 6 Fit data to polynomial
%—————————————————————
PolyData=polynomialfit(edgeL,edgeR,[x0L,y0L],[x0R,y0R]);
f6h=figure;
imshow(burnedImage)
hold on
t=linspace(-3,3);
plot((x0L-x0R)*t+x0R,(y0L-y0R)*t+y0R,’r–‘,’LineWidth’,2)
plot(PolyData.EvalPolyL(:,1),PolyData.EvalPolyL(:,2),’r’,’LineWidth’,2)
plot(PolyData.EvalPolyR(:,1),PolyData.EvalPolyR(:,2),’b’,’LineWidth’,2)
radius=500;
tilt=atand((y0R-y0L)/(x0R-x0L));
plot([PolyData.TLL(1),PolyData.TLL(1)+radius*cosd(PolyData.CAL-tilt)],[PolyData.TLL(2),PolyData.TLL(2)-radius*sind(PolyData.CAL-tilt)],’LineWidth’, 2,’color’,’g’)
plot([PolyData.TLR(1),PolyData.TLR(1)-radius*cosd(PolyData.CAR+tilt)],[PolyData.TLR(2),PolyData.TLR(2)-radius*sind(PolyData.CAR+tilt)],’LineWidth’, 2,’color’,’g’)
legend([‘contact angles, CA left= ‘,num2str(PolyData.CAL),’ CA Right= ‘,num2str(PolyData.CAR)])
set(f6h,’Units’,’normalized’,’Position’,[0.62,0.3,0.3,0.3])
display([‘Polynomial fit return the contact angles, CA Left=’,num2str(PolyData.CAL),’ CA Right=’,num2str(PolyData.CAR)])
% % Store data in the table
imageNumbers(k) = k;
CAL_values(k) = PolyData.CAL;
CAR_values(k) = PolyData.CAR;
% Save processed image to a new folder
if ~exist(output_folder, ‘dir’)
mkdir(output_folder);
end
% Save processed image in the specified formats
[~, name, ext] = fileparts(filename);
processed_filename = [name ‘_processed’];
% Check if the filename already exists, if so, append a unique identifier
index = 1;
while exist(fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.jpg’]), ‘file’)
index = index + 1;
end
% Save as JPG
imwrite(burnedImage, fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.jpg’]));
% Save as FIG
saveas(f6h, fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.fig’]));
% Save result to TXT
nsave = fullfile(output_folder, [name, ‘_’, num2str(index), ‘.txt’]);
result_vary = rand(10); % Example data, replace with your actual data
save(nsave, ‘result_vary’, ‘-ASCII’);
disp([‘Processed image saved as: ‘, processed_filename]);
end
% Create table from cell arrays
tableData = table(imageNumbers, CAL_values, CAR_values);
% Save table to a text file
output_filename = fullfile(output_folder, ‘contactAngle_table_data.txt’);
writetable(tableData, output_filename, ‘Delimiter’, ‘t’);
disp([‘Table data saved as: ‘, output_filename]);
% Display the table
disp(tableData);Hello everyone
My name is Baraa, I recently started using Matlab (Bigginner), and I need your help in explaining the error I keep making in the following code. The code is supposed to measure the contact angle of a droplet based on defining the edges of the droplet, masking the capillary, dividing the pixels on the edges of the droplet by 2 (so we can have left and right), finding the reflection of each side to define the contact points between the surface and the droplet on each side, and finally connecting the contact points together. The code then fits the pixels to find the tangent and calculates the contact angle between the tangent and the line between the contact points.
The main problem is that the code doesn’t work with all droplets and most of the time I have errors with droplets with high wettability and high volume (the droplets spread on the surface). The error message is as follows:
Index in position 1 exceeds array bounds. Index must not exceed 1113.
Error in findreflection (line 50)
x2=trace(index+n2:index+n-1,2);
Error in contactAngleImageAnalysis (line 104)
[x0L,y0L,indexL]=findreflection([edgeL.x,edgeL.y],70,0); % change the last entry (160) to zero and see what happens
How can I modify the code to make it suitable for any droplet volume?
P.S
The code always fails to read this image (Co-Eth-1, see attached) and it reads probably reads this image (Co-Eth-1b, see attached). Please refer to the two images.
Thank you very much in advance
clc
clear all
close all
addpath(genpath("C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopcodesContact Angle FittingScriptsSubpixel Matlab v2.11"));
addpath(genpath("C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopcodesContact Angle FittingScripts"));
main_path = "C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopIMAGES25.06.24";
output_folder = "C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopsessileDrop_processed";
%these are the coordinates of the polygon to mask the cannula
Xright=3100;%this the X value on the right side of the ploygon and it represents top and bottom if the right side of the polygon.
Xleft=2800;%this is the X value of the left side of the ploygon and it represents both top and bottom x cordinates
Y_top=0;% this is the y value on the top side of the polygon for both left and right side
Y_bottom=2050;% this is the y value of the bottom side of the ploygon for both left and right side
%******************************pixel intensity***************************
pixelValue=255;
%***********************threshold to be used*****************************
trsh_sub=4;
% Read a group of images from a folder
imageFiles = dir(fullfile(main_path, ‘*.png’)); % Assuming images are in PNG format
numImages = input(‘Enter the number of images to work with: ‘);
% Create cell arrays to store data
imageNumbers = zeros(numImages, 1);
CAL_values = zeros(numImages, 1);
CAR_values = zeros(numImages, 1);
for k = 1:numImages
% Load image
filename = imageFiles(k).name;
im_load = fullfile(main_path, filename);
im = imread(im_load);
%—————————————————————–
% Masking the cannula
%—————————————————————–
% Define the coordinates of the four points
maskSize = size(im);
pointCoordinates = [Xleft, Y_bottom; Xright, Y_bottom; Xright, Y_top; Xleft, Y_top];
mask = zeros(maskSize(1), maskSize(2));
mask = poly2mask(pointCoordinates(:, 1), pointCoordinates(:, 2), maskSize(1), maskSize(2));
burnedImage = im;
burnedImage(mask) = pixelValue;
%—————————————————————
% Step 2 Detect boundaries in image
%—————————————————————
[edges, RI] = subpixelEdges(burnedImage, trsh_sub);
im_size=size(burnedImage);
im_size=size(burnedImage);
points = detectHarrisFeatures(burnedImage);
strongest = selectStrongest(points,10);
f2h=figure;
imshow(burnedImage)
hold on
plot(edges.x,edges.y,’r.’,’LineWidth’,2)
% plot(edges.x(1), edges.y(1),’b*’)
% plot(edges.x(im_size(1)),edges.y(im_size(2)),’g*’)
plot(strongest)
set(f2h,’Units’,’normalized’,’Position’,[0.31,0.6,0.3,0.3])
%—————————————————————
% Step 3 Select longes boundary in image
%—————————————————————
longestedge=findlongestedge(edges,size(burnedImage),5);
f3h=figure;
imshow(burnedImage)
hold on
plot(longestedge.x,longestedge.y,’r.’,’LineWidth’,2)
set(f3h,’Units’,’normalized’,’Position’,[0.62,0.6,0.3,0.3])
%—————————————————————
% Step 4 Split edge into left and right and sort it
%—————————————————————
[edgeL,edgeR]=leftrightedges(longestedge);
f4h=figure;
imshow(burnedImage)
hold on
plot(edgeL.x,edgeL.y,’r’,’LineWidth’,2)
plot(edgeR.x,edgeR.y,’b’,’LineWidth’,2)
set(f4h,’Units’,’normalized’,’Position’,[0.0,0.3,0.3,0.3])
%—————————————————————
% Step 5 Find reflection
%—————————————————————
[x0L,y0L,indexL]=findreflection([edgeL.x,edgeL.y],70,0); % change the last entry (160) to zero and see what happens
[x0R,y0R,indexR]=findreflection([edgeR.x,edgeR.y],60,0);
f5h=figure;
imshow(burnedImage)
hold on
plot(edgeL.x,edgeL.y,’r’,’LineWidth’,2)
plot(edgeR.x,edgeR.y,’b’,’LineWidth’,2)
plot(x0L,y0L,’yx’,’MarkerSize’,10,’LineWidth’,2)
plot(x0R,y0R,’yx’,’MarkerSize’,10,’LineWidth’,2)
t=linspace(-3,3);
plot((x0L-x0R)*t+x0R,(y0L-y0R)*t+y0R,’r–‘,’LineWidth’,2)
set(f5h,’Units’,’normalized’,’Position’,[0.31,0.3,0.3,0.3])
%—————————————————————
% Step 6 Fit data to polynomial
%—————————————————————
PolyData=polynomialfit(edgeL,edgeR,[x0L,y0L],[x0R,y0R]);
f6h=figure;
imshow(burnedImage)
hold on
t=linspace(-3,3);
plot((x0L-x0R)*t+x0R,(y0L-y0R)*t+y0R,’r–‘,’LineWidth’,2)
plot(PolyData.EvalPolyL(:,1),PolyData.EvalPolyL(:,2),’r’,’LineWidth’,2)
plot(PolyData.EvalPolyR(:,1),PolyData.EvalPolyR(:,2),’b’,’LineWidth’,2)
radius=500;
tilt=atand((y0R-y0L)/(x0R-x0L));
plot([PolyData.TLL(1),PolyData.TLL(1)+radius*cosd(PolyData.CAL-tilt)],[PolyData.TLL(2),PolyData.TLL(2)-radius*sind(PolyData.CAL-tilt)],’LineWidth’, 2,’color’,’g’)
plot([PolyData.TLR(1),PolyData.TLR(1)-radius*cosd(PolyData.CAR+tilt)],[PolyData.TLR(2),PolyData.TLR(2)-radius*sind(PolyData.CAR+tilt)],’LineWidth’, 2,’color’,’g’)
legend([‘contact angles, CA left= ‘,num2str(PolyData.CAL),’ CA Right= ‘,num2str(PolyData.CAR)])
set(f6h,’Units’,’normalized’,’Position’,[0.62,0.3,0.3,0.3])
display([‘Polynomial fit return the contact angles, CA Left=’,num2str(PolyData.CAL),’ CA Right=’,num2str(PolyData.CAR)])
% % Store data in the table
imageNumbers(k) = k;
CAL_values(k) = PolyData.CAL;
CAR_values(k) = PolyData.CAR;
% Save processed image to a new folder
if ~exist(output_folder, ‘dir’)
mkdir(output_folder);
end
% Save processed image in the specified formats
[~, name, ext] = fileparts(filename);
processed_filename = [name ‘_processed’];
% Check if the filename already exists, if so, append a unique identifier
index = 1;
while exist(fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.jpg’]), ‘file’)
index = index + 1;
end
% Save as JPG
imwrite(burnedImage, fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.jpg’]));
% Save as FIG
saveas(f6h, fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.fig’]));
% Save result to TXT
nsave = fullfile(output_folder, [name, ‘_’, num2str(index), ‘.txt’]);
result_vary = rand(10); % Example data, replace with your actual data
save(nsave, ‘result_vary’, ‘-ASCII’);
disp([‘Processed image saved as: ‘, processed_filename]);
end
% Create table from cell arrays
tableData = table(imageNumbers, CAL_values, CAR_values);
% Save table to a text file
output_filename = fullfile(output_folder, ‘contactAngle_table_data.txt’);
writetable(tableData, output_filename, ‘Delimiter’, ‘t’);
disp([‘Table data saved as: ‘, output_filename]);
% Display the table
disp(tableData); Hello everyone
My name is Baraa, I recently started using Matlab (Bigginner), and I need your help in explaining the error I keep making in the following code. The code is supposed to measure the contact angle of a droplet based on defining the edges of the droplet, masking the capillary, dividing the pixels on the edges of the droplet by 2 (so we can have left and right), finding the reflection of each side to define the contact points between the surface and the droplet on each side, and finally connecting the contact points together. The code then fits the pixels to find the tangent and calculates the contact angle between the tangent and the line between the contact points.
The main problem is that the code doesn’t work with all droplets and most of the time I have errors with droplets with high wettability and high volume (the droplets spread on the surface). The error message is as follows:
Index in position 1 exceeds array bounds. Index must not exceed 1113.
Error in findreflection (line 50)
x2=trace(index+n2:index+n-1,2);
Error in contactAngleImageAnalysis (line 104)
[x0L,y0L,indexL]=findreflection([edgeL.x,edgeL.y],70,0); % change the last entry (160) to zero and see what happens
How can I modify the code to make it suitable for any droplet volume?
P.S
The code always fails to read this image (Co-Eth-1, see attached) and it reads probably reads this image (Co-Eth-1b, see attached). Please refer to the two images.
Thank you very much in advance
clc
clear all
close all
addpath(genpath("C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopcodesContact Angle FittingScriptsSubpixel Matlab v2.11"));
addpath(genpath("C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopcodesContact Angle FittingScripts"));
main_path = "C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopIMAGES25.06.24";
output_folder = "C:UsersBara’a Al-khateebDesktopOthersStudentsGideon MensahLaptopsessileDrop_processed";
%these are the coordinates of the polygon to mask the cannula
Xright=3100;%this the X value on the right side of the ploygon and it represents top and bottom if the right side of the polygon.
Xleft=2800;%this is the X value of the left side of the ploygon and it represents both top and bottom x cordinates
Y_top=0;% this is the y value on the top side of the polygon for both left and right side
Y_bottom=2050;% this is the y value of the bottom side of the ploygon for both left and right side
%******************************pixel intensity***************************
pixelValue=255;
%***********************threshold to be used*****************************
trsh_sub=4;
% Read a group of images from a folder
imageFiles = dir(fullfile(main_path, ‘*.png’)); % Assuming images are in PNG format
numImages = input(‘Enter the number of images to work with: ‘);
% Create cell arrays to store data
imageNumbers = zeros(numImages, 1);
CAL_values = zeros(numImages, 1);
CAR_values = zeros(numImages, 1);
for k = 1:numImages
% Load image
filename = imageFiles(k).name;
im_load = fullfile(main_path, filename);
im = imread(im_load);
%—————————————————————–
% Masking the cannula
%—————————————————————–
% Define the coordinates of the four points
maskSize = size(im);
pointCoordinates = [Xleft, Y_bottom; Xright, Y_bottom; Xright, Y_top; Xleft, Y_top];
mask = zeros(maskSize(1), maskSize(2));
mask = poly2mask(pointCoordinates(:, 1), pointCoordinates(:, 2), maskSize(1), maskSize(2));
burnedImage = im;
burnedImage(mask) = pixelValue;
%—————————————————————
% Step 2 Detect boundaries in image
%—————————————————————
[edges, RI] = subpixelEdges(burnedImage, trsh_sub);
im_size=size(burnedImage);
im_size=size(burnedImage);
points = detectHarrisFeatures(burnedImage);
strongest = selectStrongest(points,10);
f2h=figure;
imshow(burnedImage)
hold on
plot(edges.x,edges.y,’r.’,’LineWidth’,2)
% plot(edges.x(1), edges.y(1),’b*’)
% plot(edges.x(im_size(1)),edges.y(im_size(2)),’g*’)
plot(strongest)
set(f2h,’Units’,’normalized’,’Position’,[0.31,0.6,0.3,0.3])
%—————————————————————
% Step 3 Select longes boundary in image
%—————————————————————
longestedge=findlongestedge(edges,size(burnedImage),5);
f3h=figure;
imshow(burnedImage)
hold on
plot(longestedge.x,longestedge.y,’r.’,’LineWidth’,2)
set(f3h,’Units’,’normalized’,’Position’,[0.62,0.6,0.3,0.3])
%—————————————————————
% Step 4 Split edge into left and right and sort it
%—————————————————————
[edgeL,edgeR]=leftrightedges(longestedge);
f4h=figure;
imshow(burnedImage)
hold on
plot(edgeL.x,edgeL.y,’r’,’LineWidth’,2)
plot(edgeR.x,edgeR.y,’b’,’LineWidth’,2)
set(f4h,’Units’,’normalized’,’Position’,[0.0,0.3,0.3,0.3])
%—————————————————————
% Step 5 Find reflection
%—————————————————————
[x0L,y0L,indexL]=findreflection([edgeL.x,edgeL.y],70,0); % change the last entry (160) to zero and see what happens
[x0R,y0R,indexR]=findreflection([edgeR.x,edgeR.y],60,0);
f5h=figure;
imshow(burnedImage)
hold on
plot(edgeL.x,edgeL.y,’r’,’LineWidth’,2)
plot(edgeR.x,edgeR.y,’b’,’LineWidth’,2)
plot(x0L,y0L,’yx’,’MarkerSize’,10,’LineWidth’,2)
plot(x0R,y0R,’yx’,’MarkerSize’,10,’LineWidth’,2)
t=linspace(-3,3);
plot((x0L-x0R)*t+x0R,(y0L-y0R)*t+y0R,’r–‘,’LineWidth’,2)
set(f5h,’Units’,’normalized’,’Position’,[0.31,0.3,0.3,0.3])
%—————————————————————
% Step 6 Fit data to polynomial
%—————————————————————
PolyData=polynomialfit(edgeL,edgeR,[x0L,y0L],[x0R,y0R]);
f6h=figure;
imshow(burnedImage)
hold on
t=linspace(-3,3);
plot((x0L-x0R)*t+x0R,(y0L-y0R)*t+y0R,’r–‘,’LineWidth’,2)
plot(PolyData.EvalPolyL(:,1),PolyData.EvalPolyL(:,2),’r’,’LineWidth’,2)
plot(PolyData.EvalPolyR(:,1),PolyData.EvalPolyR(:,2),’b’,’LineWidth’,2)
radius=500;
tilt=atand((y0R-y0L)/(x0R-x0L));
plot([PolyData.TLL(1),PolyData.TLL(1)+radius*cosd(PolyData.CAL-tilt)],[PolyData.TLL(2),PolyData.TLL(2)-radius*sind(PolyData.CAL-tilt)],’LineWidth’, 2,’color’,’g’)
plot([PolyData.TLR(1),PolyData.TLR(1)-radius*cosd(PolyData.CAR+tilt)],[PolyData.TLR(2),PolyData.TLR(2)-radius*sind(PolyData.CAR+tilt)],’LineWidth’, 2,’color’,’g’)
legend([‘contact angles, CA left= ‘,num2str(PolyData.CAL),’ CA Right= ‘,num2str(PolyData.CAR)])
set(f6h,’Units’,’normalized’,’Position’,[0.62,0.3,0.3,0.3])
display([‘Polynomial fit return the contact angles, CA Left=’,num2str(PolyData.CAL),’ CA Right=’,num2str(PolyData.CAR)])
% % Store data in the table
imageNumbers(k) = k;
CAL_values(k) = PolyData.CAL;
CAR_values(k) = PolyData.CAR;
% Save processed image to a new folder
if ~exist(output_folder, ‘dir’)
mkdir(output_folder);
end
% Save processed image in the specified formats
[~, name, ext] = fileparts(filename);
processed_filename = [name ‘_processed’];
% Check if the filename already exists, if so, append a unique identifier
index = 1;
while exist(fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.jpg’]), ‘file’)
index = index + 1;
end
% Save as JPG
imwrite(burnedImage, fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.jpg’]));
% Save as FIG
saveas(f6h, fullfile(output_folder, [processed_filename, ‘_’, num2str(index), ‘.fig’]));
% Save result to TXT
nsave = fullfile(output_folder, [name, ‘_’, num2str(index), ‘.txt’]);
result_vary = rand(10); % Example data, replace with your actual data
save(nsave, ‘result_vary’, ‘-ASCII’);
disp([‘Processed image saved as: ‘, processed_filename]);
end
% Create table from cell arrays
tableData = table(imageNumbers, CAL_values, CAR_values);
% Save table to a text file
output_filename = fullfile(output_folder, ‘contactAngle_table_data.txt’);
writetable(tableData, output_filename, ‘Delimiter’, ‘t’);
disp([‘Table data saved as: ‘, output_filename]);
% Display the table
disp(tableData); droplet, wettability, contact angle MATLAB Answers — New Questions
Unrecognized function or variable ‘asbQuadcopterStart’.
I got the same problem as another case followed:
Unrecognized function or variable ‘asbQuadcopterStart’. – MATLAB Answers – MATLAB Central (mathworks.com)
Error Msg: Unrecognized function or variable ‘asbQuadcopterStart’.
But I am sure that both
Aerospace Blockset
Aerospace Toolbox
are installed in my computer. Which can be both showed on the attached image.
So, Which step I missed?
Thanks a lot!I got the same problem as another case followed:
Unrecognized function or variable ‘asbQuadcopterStart’. – MATLAB Answers – MATLAB Central (mathworks.com)
Error Msg: Unrecognized function or variable ‘asbQuadcopterStart’.
But I am sure that both
Aerospace Blockset
Aerospace Toolbox
are installed in my computer. Which can be both showed on the attached image.
So, Which step I missed?
Thanks a lot! I got the same problem as another case followed:
Unrecognized function or variable ‘asbQuadcopterStart’. – MATLAB Answers – MATLAB Central (mathworks.com)
Error Msg: Unrecognized function or variable ‘asbQuadcopterStart’.
But I am sure that both
Aerospace Blockset
Aerospace Toolbox
are installed in my computer. Which can be both showed on the attached image.
So, Which step I missed?
Thanks a lot! asbquadcopterstart, aerospace MATLAB Answers — New Questions
How can I express all the variables Vcm1, Vcm2, Vcm3, Vcm4 in num2str without getting an error?
annotation(‘textbox’,dim,’String’,((num2str(Vcm1),num2str(Vcm2),num2str(Vcm3),num2str(Vcm4)), ‘FontSize’;15)annotation(‘textbox’,dim,’String’,((num2str(Vcm1),num2str(Vcm2),num2str(Vcm3),num2str(Vcm4)), ‘FontSize’;15) annotation(‘textbox’,dim,’String’,((num2str(Vcm1),num2str(Vcm2),num2str(Vcm3),num2str(Vcm4)), ‘FontSize’;15) num2str MATLAB Answers — New Questions
calculated columns
Hello. I would like to know if sharepoint calculated columns can reference a previous element of that same column or another. In Excel, for example, I can make a formula that is B11=B10+A10.
But in a sharepoint list the column name is referenced to calculate something.
Thanks in advance
Hello. I would like to know if sharepoint calculated columns can reference a previous element of that same column or another. In Excel, for example, I can make a formula that is B11=B10+A10.
But in a sharepoint list the column name is referenced to calculate something.
Thanks in advance Read More
hotmail accounts
I am using e mail with my 2 hotmail accounts on my Apple i phone SE. Recently I have been unable to send mail getting a message saying that account passwords are incorrect. I’m wondering if this is anything related to the message I received from MS about third party platforms. I have read this message several times but am baffled by the jargon.
I am using e mail with my 2 hotmail accounts on my Apple i phone SE. Recently I have been unable to send mail getting a message saying that account passwords are incorrect. I’m wondering if this is anything related to the message I received from MS about third party platforms. I have read this message several times but am baffled by the jargon. Read More
How do I “auto populate” a field on Access Forms
When I select the drop-down menu under ‘Proto category’ I need to have ‘ category time’ auto-populate against what info it has. For example, they both share one table. One scenario would be ‘if the proto category is T1 then the category time is 3 hours’. My table has each row as to what it needs to be per category.
When I select the drop-down menu under ‘Proto category’ I need to have ‘ category time’ auto-populate against what info it has. For example, they both share one table. One scenario would be ‘if the proto category is T1 then the category time is 3 hours’. My table has each row as to what it needs to be per category. Read More
Date formatting
Hi
I need a formula that turns this value 20060323 (YYYMMDD) into a short date – 23/03/2006 (DD/MM/YYY)
I have had a google and a look on this messageboard but I haven’t had much luck.
Thank you
Hi I need a formula that turns this value 20060323 (YYYMMDD) into a short date – 23/03/2006 (DD/MM/YYY) I have had a google and a look on this messageboard but I haven’t had much luck. Thank you Read More
Displaying most recent value in a horizontal array?
Hi,
I have an array full of prices and 1 date column. I need to display the most recent value of each row’s array that are all equal to today’s date. I plan to sum all the numbers eventually.
Ex:
TODAY’S DATE: July 4th 2024
18-May$63.00$86.00
04-Jul$134.00$34.00$50.00 04-Jul$25.00
Output:
78
50
25
(Summed up this would be 153)
Thanks in advance!
Hi,I have an array full of prices and 1 date column. I need to display the most recent value of each row’s array that are all equal to today’s date. I plan to sum all the numbers eventually.Ex:TODAY’S DATE: July 4th 202404-Jul$14.00$45.00 78.0018-May$63.00$86.00$92.00 04-Jul$134.00$34.00$50.00 04-Jul$25.00 Output:785025(Summed up this would be 153)Thanks in advance! Read More
plotting Graph in 3D help
function basic
K=0.2; n=0.3; lam=0.1;
%Defining parameters
sol1 = bvpinit(linspace(0,6,300),[0 0 0 0 0]);
sol = bvp4c(@bvp2D, @bc2D, sol1);
x = sol.x;
y = sol.y;
%%% Plotting of the velocity
figure (1)
plot(x, y(2, 🙂 ,’linewidth’, 1.5);
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘f^{prime}(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
%% Residual of the boundary conditions
function residual = bc2D(y0, yinf)
residual=[y0(1); y0(2) – 1; y0(4)+n*y0(3); yinf(2)-lam; yinf(4)];
end
%% System of First Order ODEs
function yvector = bvp2D(~,y)
yy1 =(1/(1+K))*(-y(1)*y(3)+y(2)^2-K*y(5)-lam^2);
yy2 =(2/(2+K))*(-y(1)*y(5)+y(2)*y(4)+K*(2*y(4)+y(3)));
yvector = [y(2);y(3);yy1; y(5); yy2];
end
end
i want to plot this graph in 3D, how can I?function basic
K=0.2; n=0.3; lam=0.1;
%Defining parameters
sol1 = bvpinit(linspace(0,6,300),[0 0 0 0 0]);
sol = bvp4c(@bvp2D, @bc2D, sol1);
x = sol.x;
y = sol.y;
%%% Plotting of the velocity
figure (1)
plot(x, y(2, 🙂 ,’linewidth’, 1.5);
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘f^{prime}(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
%% Residual of the boundary conditions
function residual = bc2D(y0, yinf)
residual=[y0(1); y0(2) – 1; y0(4)+n*y0(3); yinf(2)-lam; yinf(4)];
end
%% System of First Order ODEs
function yvector = bvp2D(~,y)
yy1 =(1/(1+K))*(-y(1)*y(3)+y(2)^2-K*y(5)-lam^2);
yy2 =(2/(2+K))*(-y(1)*y(5)+y(2)*y(4)+K*(2*y(4)+y(3)));
yvector = [y(2);y(3);yy1; y(5); yy2];
end
end
i want to plot this graph in 3D, how can I? function basic
K=0.2; n=0.3; lam=0.1;
%Defining parameters
sol1 = bvpinit(linspace(0,6,300),[0 0 0 0 0]);
sol = bvp4c(@bvp2D, @bc2D, sol1);
x = sol.x;
y = sol.y;
%%% Plotting of the velocity
figure (1)
plot(x, y(2, 🙂 ,’linewidth’, 1.5);
hold on
xlabel(‘eta’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
ylabel(‘f^{prime}(eta)’, ‘fontweight’, ‘bold’, ‘fontsize’, 16)
%% Residual of the boundary conditions
function residual = bc2D(y0, yinf)
residual=[y0(1); y0(2) – 1; y0(4)+n*y0(3); yinf(2)-lam; yinf(4)];
end
%% System of First Order ODEs
function yvector = bvp2D(~,y)
yy1 =(1/(1+K))*(-y(1)*y(3)+y(2)^2-K*y(5)-lam^2);
yy2 =(2/(2+K))*(-y(1)*y(5)+y(2)*y(4)+K*(2*y(4)+y(3)));
yvector = [y(2);y(3);yy1; y(5); yy2];
end
end
i want to plot this graph in 3D, how can I? bvp4c, 2d plotting, 3d plotting MATLAB Answers — New Questions
What is Mathworks Service Host?
I’m running Matlab 2023b on Ubuntu.
I’m just curious what this process is that’s been put in .config/autostart//mathworks-service-host.desktop to start at login?
Matlab starts fine without it but when I close Matlab, a process namber MathworksServiceHost keeps running.
It’s not a nice idea of having matlab-related processes running on the system after the application has been shut down. I have not noticed it on other version of Matlab. At least you should notify the user that a process is added to the autostart folder, and what it does.I’m running Matlab 2023b on Ubuntu.
I’m just curious what this process is that’s been put in .config/autostart//mathworks-service-host.desktop to start at login?
Matlab starts fine without it but when I close Matlab, a process namber MathworksServiceHost keeps running.
It’s not a nice idea of having matlab-related processes running on the system after the application has been shut down. I have not noticed it on other version of Matlab. At least you should notify the user that a process is added to the autostart folder, and what it does. I’m running Matlab 2023b on Ubuntu.
I’m just curious what this process is that’s been put in .config/autostart//mathworks-service-host.desktop to start at login?
Matlab starts fine without it but when I close Matlab, a process namber MathworksServiceHost keeps running.
It’s not a nice idea of having matlab-related processes running on the system after the application has been shut down. I have not noticed it on other version of Matlab. At least you should notify the user that a process is added to the autostart folder, and what it does. autostart, mathworksservicehost MATLAB Answers — New Questions
How to determine sampling frequency of wgn?
Hello there,
I’m trying to understand noise analysis and the concept of power spectral density. I’ve found this article:
https://pure.mpg.de/pubman/faces/ViewItemOverviewPage.jsp?itemId=item_152164
Which was really helpful and interesting, but I’ve encountered some problems while trying to put it in practise.
For convenience I wanted to generate white noise (mainly because of its flat spectral density) via wgn funtion and then calculate its PSD. If i understood it correctly, wgn creates discrete samples, which completely lack any relatationship to time.
And here comes my problem – while normalizing the results, equivalent noise bandwidth is dependent on sampling rate and so is PSD:
,
where w are window function values, S are complex results from fft function.
By experimenting with code I came upon sampling rate of 2 samples/s, when mean power of PSD was getting close to 5 dB. Unfortunatelly, I still cannot confidently explain this.
Is there please any way to obtain "realistic" white noise samples in MATLAB? Or do I have to add white noise to (co)sine signal with known sampling? If I’m missing something, please let me know.
Thank you in advance,
Jan
CODE:
% Size parameters
L = pow2(16);
iterations = 100;
% ??? (Guessed value)
fs = 2;
% Frequency resolution
f_res = fs/L;
% Create noise with power of 5 dBW
data = wgn(L,iterations, 5);
% Apply Hann window
h = hann(L);
w = ones(L,iterations) .* h;
data = data .* w;
% Calculate normalizing factor S2
S2 = sum(h.^2);
% Calculate fft
S = fft(data,L,1);
S = S .* conj(S);
% Average power spectrum
for i = 1:L
PSD(i) = mean(S(i,:));
end
% Normalize results
PSD = 2 * PSD / (fs * S2);
% Discard symmectric part
PSD = PSD(1:(L/2+1));
% PSD in dB(W)
PSD = 10*log10(PSD);
% Mean value of PSD
display("Power = " + mean(PSD) + " dB");
% Calculate frequency
f = (0:(L/2)) * f_res;
% Plot data
figure
plot(f,PSD)
xlabel("f [Hz]")
ylabel("PSD [dB/Hz]")Hello there,
I’m trying to understand noise analysis and the concept of power spectral density. I’ve found this article:
https://pure.mpg.de/pubman/faces/ViewItemOverviewPage.jsp?itemId=item_152164
Which was really helpful and interesting, but I’ve encountered some problems while trying to put it in practise.
For convenience I wanted to generate white noise (mainly because of its flat spectral density) via wgn funtion and then calculate its PSD. If i understood it correctly, wgn creates discrete samples, which completely lack any relatationship to time.
And here comes my problem – while normalizing the results, equivalent noise bandwidth is dependent on sampling rate and so is PSD:
,
where w are window function values, S are complex results from fft function.
By experimenting with code I came upon sampling rate of 2 samples/s, when mean power of PSD was getting close to 5 dB. Unfortunatelly, I still cannot confidently explain this.
Is there please any way to obtain "realistic" white noise samples in MATLAB? Or do I have to add white noise to (co)sine signal with known sampling? If I’m missing something, please let me know.
Thank you in advance,
Jan
CODE:
% Size parameters
L = pow2(16);
iterations = 100;
% ??? (Guessed value)
fs = 2;
% Frequency resolution
f_res = fs/L;
% Create noise with power of 5 dBW
data = wgn(L,iterations, 5);
% Apply Hann window
h = hann(L);
w = ones(L,iterations) .* h;
data = data .* w;
% Calculate normalizing factor S2
S2 = sum(h.^2);
% Calculate fft
S = fft(data,L,1);
S = S .* conj(S);
% Average power spectrum
for i = 1:L
PSD(i) = mean(S(i,:));
end
% Normalize results
PSD = 2 * PSD / (fs * S2);
% Discard symmectric part
PSD = PSD(1:(L/2+1));
% PSD in dB(W)
PSD = 10*log10(PSD);
% Mean value of PSD
display("Power = " + mean(PSD) + " dB");
% Calculate frequency
f = (0:(L/2)) * f_res;
% Plot data
figure
plot(f,PSD)
xlabel("f [Hz]")
ylabel("PSD [dB/Hz]") Hello there,
I’m trying to understand noise analysis and the concept of power spectral density. I’ve found this article:
https://pure.mpg.de/pubman/faces/ViewItemOverviewPage.jsp?itemId=item_152164
Which was really helpful and interesting, but I’ve encountered some problems while trying to put it in practise.
For convenience I wanted to generate white noise (mainly because of its flat spectral density) via wgn funtion and then calculate its PSD. If i understood it correctly, wgn creates discrete samples, which completely lack any relatationship to time.
And here comes my problem – while normalizing the results, equivalent noise bandwidth is dependent on sampling rate and so is PSD:
,
where w are window function values, S are complex results from fft function.
By experimenting with code I came upon sampling rate of 2 samples/s, when mean power of PSD was getting close to 5 dB. Unfortunatelly, I still cannot confidently explain this.
Is there please any way to obtain "realistic" white noise samples in MATLAB? Or do I have to add white noise to (co)sine signal with known sampling? If I’m missing something, please let me know.
Thank you in advance,
Jan
CODE:
% Size parameters
L = pow2(16);
iterations = 100;
% ??? (Guessed value)
fs = 2;
% Frequency resolution
f_res = fs/L;
% Create noise with power of 5 dBW
data = wgn(L,iterations, 5);
% Apply Hann window
h = hann(L);
w = ones(L,iterations) .* h;
data = data .* w;
% Calculate normalizing factor S2
S2 = sum(h.^2);
% Calculate fft
S = fft(data,L,1);
S = S .* conj(S);
% Average power spectrum
for i = 1:L
PSD(i) = mean(S(i,:));
end
% Normalize results
PSD = 2 * PSD / (fs * S2);
% Discard symmectric part
PSD = PSD(1:(L/2+1));
% PSD in dB(W)
PSD = 10*log10(PSD);
% Mean value of PSD
display("Power = " + mean(PSD) + " dB");
% Calculate frequency
f = (0:(L/2)) * f_res;
% Plot data
figure
plot(f,PSD)
xlabel("f [Hz]")
ylabel("PSD [dB/Hz]") psd, noise analysis, white noise, wgn, noise, matlab MATLAB Answers — New Questions
File Explorer windows pops up out of nowhere
Since a day or so, at seemingly random moments a File Explorer window pops up in front of everything. This started to happen shortly after I had installed ExplorerPatcher. I am 100% positive that it never happened before, I would have remembered.
This post You’re Not Alone: Windows 11 Is Randomly Opening File Explorer says that this is a Windows 11 issue (which seems unlikely to me as I never saw it before installing EP), and that it does not create a new window but only brings an existing window to the foreground (which is pertinently untrue, it does create a new file explorer window). Some further investigation suggests that it happens when an application that was using full screen switches back to normal display (at least that is how I can reliably reproduce it).
It is not a big deal but it’s annoying, and somewhat spoils my joy in having discovered ExplorerPatcher. Any ideas out there ?
Since a day or so, at seemingly random moments a File Explorer window pops up in front of everything. This started to happen shortly after I had installed ExplorerPatcher. I am 100% positive that it never happened before, I would have remembered. This post You’re Not Alone: Windows 11 Is Randomly Opening File Explorer says that this is a Windows 11 issue (which seems unlikely to me as I never saw it before installing EP), and that it does not create a new window but only brings an existing window to the foreground (which is pertinently untrue, it does create a new file explorer window). Some further investigation suggests that it happens when an application that was using full screen switches back to normal display (at least that is how I can reliably reproduce it). It is not a big deal but it’s annoying, and somewhat spoils my joy in having discovered ExplorerPatcher. Any ideas out there ? Read More
Microsoft Project for the web API
Hello community, I need to work with MS Project for web over api, CRUD projects, CRUD tasks and etc from https://project.microsoft.com/ with using an API.
I searched and couldn’t find any documentation or SDK to do it.
Only one page from offecial source about API here https://learn.microsoft.com/en-us/project-for-the-web/projectforweb-admin-home
that point to https://devblogs.microsoft.com/microsoft365dev/tag/project/
The both links without any API description for Project for the web.
Is there any documentation for an API to integrate with Project for the web?
Thank you
Hello community, I need to work with MS Project for web over api, CRUD projects, CRUD tasks and etc from https://project.microsoft.com/ with using an API. I searched and couldn’t find any documentation or SDK to do it.Only one page from offecial source about API here https://learn.microsoft.com/en-us/project-for-the-web/projectforweb-admin-homethat point to https://devblogs.microsoft.com/microsoft365dev/tag/project/The both links without any API description for Project for the web. Is there any documentation for an API to integrate with Project for the web?Thank you Read More
Here’s what I get when I want to check my operating system build:
Here’s what I get when I want to check my operating system build:
Here’s what I get when I want to check my operating system build:Well actually it is so very tiny and almost unreadable. I can’t figure out how to get the font large enough that I can read it. Read More