Month: June 2024
Communications Site – sharing content externally
We are a small charity with a small team of volunteers and members.
I would like to setup a dedicated MS 365 Communication site to share content such as newsletters with our members. Members are external to our 365 environment, but are added as contacts – a distribution list has been created using the contacts.
I’ve looked at many sites, YouTube videos etc. but struggling to make this work in a safe way. I’m assuming a dedicated SharePoint comms site would be best for security reasons, perhaps allowing specific privileges, but any help appreciated?
We are a small charity with a small team of volunteers and members. I would like to setup a dedicated MS 365 Communication site to share content such as newsletters with our members. Members are external to our 365 environment, but are added as contacts – a distribution list has been created using the contacts. I’ve looked at many sites, YouTube videos etc. but struggling to make this work in a safe way. I’m assuming a dedicated SharePoint comms site would be best for security reasons, perhaps allowing specific privileges, but any help appreciated? Read More
Sincronización outlook
He instalado la app de outllook, en un galaxy S24, android. Tengo 3 cuentas configuardas, dos son IMAP y la otra no. En las dos cuentas IMAP tengo problemas con los emails porque llegan horas después de que han sido enviados, no llegan inmediatamente. El envio de emails funciona perfectamente. La cuenta que no es IMAP funciona perfectamente en el envío y la repeción de emails, estos llegan inmediatamente. El personal de Microsoft me ha derivado a este chat porque no saben como resolver el problema. Gracias
He instalado la app de outllook, en un galaxy S24, android. Tengo 3 cuentas configuardas, dos son IMAP y la otra no. En las dos cuentas IMAP tengo problemas con los emails porque llegan horas después de que han sido enviados, no llegan inmediatamente. El envio de emails funciona perfectamente. La cuenta que no es IMAP funciona perfectamente en el envío y la repeción de emails, estos llegan inmediatamente. El personal de Microsoft me ha derivado a este chat porque no saben como resolver el problema. Gracias Read More
How can I add the department to the evaluation of a Forms survey in Excel?
Hello,
I conducted a survey using Forms and generated a corresponding dataset.
For the evaluation, I also need the respective department of the participants as additional information for sorting in Excel.
How can this criterion be integrated into the evaluation?
Thank you and best regards.
Hello,I conducted a survey using Forms and generated a corresponding dataset.For the evaluation, I also need the respective department of the participants as additional information for sorting in Excel.How can this criterion be integrated into the evaluation?Thank you and best regards. Read More
Security review for Microsoft Edge version 126
We are pleased to announce the security review for Microsoft Edge, version 126!
We have reviewed the new settings in Microsoft Edge version 126 and determined that there are no additional security settings that require enforcement. The Microsoft Edge version 117 security baseline continues to be our recommended configuration which can be downloaded from the Microsoft Security Compliance Toolkit.
Microsoft Edge version 126 introduced 2 new computer settings and 2 new user settings. We have included a spreadsheet listing the new settings in the release to make it easier for you to find them.
One thing to note with this release we have added configurable settings for Copilot. Something to consider based on your organizations policy
As a friendly reminder, all available settings for Microsoft Edge are documented here, and all available settings for Microsoft Edge Update are documented here.
Please continue to give us feedback through the Security Baselines Discussion site or this post.
Microsoft Tech Community – Latest Blogs –Read More
Azure GenAI Application Deployment Strategy
Synopsis
The latest advancements in Artificial Intelligence (AI), particularly the emergence of Generative AI (GenAI) and its Large Language Models (LLM), have sparked a new wave of business opportunities across various industries. Business leaders are eager to harness this new AI wave to enhance, automate, and accelerate their operations for the benefit of their businesses. Applications driven by GenAI are helping businesses to not only monetise existing revenue streams but also to create new ones.
However, adopting new technologies always comes with challenges. A methodical and streamlined approach is essential for the successful adoption of these technologies; otherwise, there could be significant negative impacts on the technology onboarding process, the time required for adoption, learning to implement, selecting the appropriate LLM models, and integrating these technologies into the business. It also involves identifying suitable use cases, references, best practices, and frameworks, as well as considering trials of the technologies, such as running proof of concepts, building MVP (Minimum Viable Product), and productionising GenAI applications.
We have had numerous discussions with our customers about these ongoing challenges and offering guidance throughout constantly shifting AI landscape.
In this series, we will provide approach to adopt “GenAI Application Deployment Strategy” drawing from our accumulated knowledge and field expertise.
Series:
Topic 1: How to identify the most impactful GenAI use case
Topic 2: Potential Use cases for GenAI Application
Topic 3: The Evolution of GenAI Application Deployment Strategy: Building Custom Co-Pilot (PoC)
Topic 4: The Evolution of GenAI Application Deployment Strategy: From PoC to MVP
Topic 5: The Evolution of GenAI Application Deployment Strategy: From MVP to Production
Topic 6: Value Base Delivery (VBD) to accelerate GenAI use case implementation
@Paolo Colecchia @Taonga_Banda @StephenRhodes @renbafa Morgan Gladwell
Microsoft Tech Community – Latest Blogs –Read More
MVP’s Favorite Content: Visual Studio, “Recall,” AI, AKS
In this blog series dedicated to Microsoft’s technical articles, we’ll highlight our MVPs’ favorite article along with their personal insights.
Tomomitsu Kusaba, Developer Technologies MVP, Japan
“GitHub Copilot and GitHub Copilot Chat are now integrated as features in Visual Studio 2022. Previously, they were available as extensions through the Visual Studio Marketplace. This integration into the IDE is expected to further enhance quality, expand functionality, and improve the overall user experience.”
(In Japanese, Visual Studio 2022 で GitHub Copilot と GitHub Copilot Chat が Visual Studio の機能として統合されました。今までは、Visual Studio Marketplace 拡張機能として提供されていましたが IDE の機能として統合されたことでますます品質向上と機能拡充により体験向上が期待されます。)
Tomokazu Kizawa, Windows and Devices MVP, Japan
Retrace your steps with Recall – Microsoft Support
“The “Recall” feature utilizes the capabilities of Copilot+ PC to record PC operations as screen snapshots. These recorded snapshots can be searched using natural language for both text and images, thanks to multimodal AI capabilities. The text in the search results can be extracted through optical character recognition (OCR), allowing users to copy the text. Additionally, you can open the original application where the snapshot was taken. The Recall feature significantly enhances productivity by extracting necessary information from past operation records. This article clearly explains the overview and required resources for the Recall feature.”
(In Japanese, 「Recall 機能」はCopilot+ PC の機能を活用して、PC の操作を画面のスナップショットとして記録します。記録されたスナップショットは、マルチモーダルな AI の機能により、自然言語を使って文字や画像を検索できます。検索結果のスナップショットは、文字認識により文字を抽出でき、テキストをコピーすることもできます。また、スナップショットを作成した元のアプリケーションで開くこともできます。Recall 機能は過去の操作記録から必要な情報を抽出できるため、生産性を劇的に向上させる機能と言えるでしょう。この記事はRecall 機能の概要や必要なリソースについてわかりやすく記載されています。)
*Relevant Video: 第731回 パソコンが変わる。Surfaceが変える。Copilot+ PC・新型Surface Pro 11とSurface Laptop (2024/5/26) – YouTube
Komes Chandavimol, AI MVP, Thailand
Operationalize AI responsibly with Azure AI Studio (microsoft.com)
“This session focuses not only on using AI but also on building it responsibly. Microsoft emphasizes responsible AI from the start, incorporating responsible-by-design principles, built-in tools, and configurable controls for AI governance to help organizations mitigate potential risks. Several demos on risk mitigation are featured in this session, which you should not miss. Join us to learn from young students utilizing Microsoft’s multimodal technologies and explore how to build AI responsibly.”
(In Thai, หลายๆท่านคงกำลังสร้าง AI solutions และการเริ่มต้นออกแบบ ด้วย Responsible AI เป็นสิ่งสำคัญมาก ใน session Operationalize AI responsibly with Azure AI Studio จะช่วยอธิบายถีงการออกแบบ ai อย่างมีความรับผิดชอบ ตัวอย่าง และ demo เพื่อลดความเสี่ยงที่เกิดจากการนำ LLMs มาใช้สร้าง AI Solutions.)
Shunsuke Yoshikawa, Microsoft Azure MVP, Japan
AKS Automatic – AKS Engineering Blog (azure.github.io)
“This article introduces a new option for AKS announced at Microsoft Build 2024. AKS Automatic allows for easy provisioning of AKS with configurations aligned to best practices and numerous automated operations. It’s a highly attractive new feature.”
(In Japanese, Microsoft Build 2024 で発表された、AKS の新しいオプションの紹介記事です。AKS Automatic は、簡単に AKS をプロビジョニングできる機能です。ベストプラクティスに沿った設定がされており、多くの操作が自動化されています。非常に魅力的な新機能です。)
Microsoft Tech Community – Latest Blogs –Read More
How to distinguish pressing cancel vs entering an empty string in inputdlg?
I have an input dialog box that will reopen if an invalid name is entered (it will close if more than 5 attempts is made). It is asking for a name to create a file with.
I want the user to be able to press "cancel" or the "x" (windows close button) and have the program exit, but I also want the user to not type anything and press "ok" and have it count as an incorrect attempt and reopen the box.
However, the only way I found people saying to use this is to check if the input is empty, if it is to break. However, this does not distinguish between meaningfully enterring an empty string and pressing cancel/x.
Is there a way to do what I am trying to do?
Also, if there is a better way to write the code in general, please let me know. I am open to improvements and criticism. This is my first MATLAB script I’ve written. It’s been a journey trying to learn the language/script (coming only from standard C).
Here is the snippet from my code:
while badFileName == true
attemptsLeft = num2str(5 – errorCounter);
outputName = inputdlg([‘Please enter a file name. Do not use spaces! Attempts left: ‘ attemptsLeft],’Output File Creation’);
if isempty(outputName)
return;
end
outputName = string(outputName);
badFileName = contains(outputName,illegalCharacters);
errorCounter = errorCounter+1;
if errorCounter >= 5
break
end
endI have an input dialog box that will reopen if an invalid name is entered (it will close if more than 5 attempts is made). It is asking for a name to create a file with.
I want the user to be able to press "cancel" or the "x" (windows close button) and have the program exit, but I also want the user to not type anything and press "ok" and have it count as an incorrect attempt and reopen the box.
However, the only way I found people saying to use this is to check if the input is empty, if it is to break. However, this does not distinguish between meaningfully enterring an empty string and pressing cancel/x.
Is there a way to do what I am trying to do?
Also, if there is a better way to write the code in general, please let me know. I am open to improvements and criticism. This is my first MATLAB script I’ve written. It’s been a journey trying to learn the language/script (coming only from standard C).
Here is the snippet from my code:
while badFileName == true
attemptsLeft = num2str(5 – errorCounter);
outputName = inputdlg([‘Please enter a file name. Do not use spaces! Attempts left: ‘ attemptsLeft],’Output File Creation’);
if isempty(outputName)
return;
end
outputName = string(outputName);
badFileName = contains(outputName,illegalCharacters);
errorCounter = errorCounter+1;
if errorCounter >= 5
break
end
end I have an input dialog box that will reopen if an invalid name is entered (it will close if more than 5 attempts is made). It is asking for a name to create a file with.
I want the user to be able to press "cancel" or the "x" (windows close button) and have the program exit, but I also want the user to not type anything and press "ok" and have it count as an incorrect attempt and reopen the box.
However, the only way I found people saying to use this is to check if the input is empty, if it is to break. However, this does not distinguish between meaningfully enterring an empty string and pressing cancel/x.
Is there a way to do what I am trying to do?
Also, if there is a better way to write the code in general, please let me know. I am open to improvements and criticism. This is my first MATLAB script I’ve written. It’s been a journey trying to learn the language/script (coming only from standard C).
Here is the snippet from my code:
while badFileName == true
attemptsLeft = num2str(5 – errorCounter);
outputName = inputdlg([‘Please enter a file name. Do not use spaces! Attempts left: ‘ attemptsLeft],’Output File Creation’);
if isempty(outputName)
return;
end
outputName = string(outputName);
badFileName = contains(outputName,illegalCharacters);
errorCounter = errorCounter+1;
if errorCounter >= 5
break
end
end inputdlg, matlab gui, input, loops MATLAB Answers — New Questions
What is MATLAB doing when adding multiple ZPK transfer functions together?
I am trying to add multiple zpk transfer functions by directly accessing the zeros, poles, and gains without the use of the "parallel" or "+" operations (for runtime reduction), and I was wondering what "+" does:
zero1 = [1, 2];
pole1 = [3, 4];
gain1 = 2;
tf1 = zpk(zero1, pole1, gain1)
% tf1 =
%
% 2 (s-1) (s-2)
% ————-
% (s-3) (s-4)
zero2 = [-1, -2];
pole2 = [-3, -4];
gain2 = -2;
tf2 = zpk(zero2, pole2, gain2)
% tf2 =
%
% -2 (s+1) (s+2)
% ————–
% (s+3) (s+4)
tf = tf1 + tf2
% tf =
%
% 16 s (s-2.345) (s+2.345)
% ————————
% (s-3) (s-4) (s+3) (s+4)
I googled how to add two ZPK transfer functions and it said that it’s simply linearly adding them together but Matlab is definitely doing something different (as "tf" has a zero at +/- 2.345 when neither "tf1" nor "tf2" have those zeros)I am trying to add multiple zpk transfer functions by directly accessing the zeros, poles, and gains without the use of the "parallel" or "+" operations (for runtime reduction), and I was wondering what "+" does:
zero1 = [1, 2];
pole1 = [3, 4];
gain1 = 2;
tf1 = zpk(zero1, pole1, gain1)
% tf1 =
%
% 2 (s-1) (s-2)
% ————-
% (s-3) (s-4)
zero2 = [-1, -2];
pole2 = [-3, -4];
gain2 = -2;
tf2 = zpk(zero2, pole2, gain2)
% tf2 =
%
% -2 (s+1) (s+2)
% ————–
% (s+3) (s+4)
tf = tf1 + tf2
% tf =
%
% 16 s (s-2.345) (s+2.345)
% ————————
% (s-3) (s-4) (s+3) (s+4)
I googled how to add two ZPK transfer functions and it said that it’s simply linearly adding them together but Matlab is definitely doing something different (as "tf" has a zero at +/- 2.345 when neither "tf1" nor "tf2" have those zeros) I am trying to add multiple zpk transfer functions by directly accessing the zeros, poles, and gains without the use of the "parallel" or "+" operations (for runtime reduction), and I was wondering what "+" does:
zero1 = [1, 2];
pole1 = [3, 4];
gain1 = 2;
tf1 = zpk(zero1, pole1, gain1)
% tf1 =
%
% 2 (s-1) (s-2)
% ————-
% (s-3) (s-4)
zero2 = [-1, -2];
pole2 = [-3, -4];
gain2 = -2;
tf2 = zpk(zero2, pole2, gain2)
% tf2 =
%
% -2 (s+1) (s+2)
% ————–
% (s+3) (s+4)
tf = tf1 + tf2
% tf =
%
% 16 s (s-2.345) (s+2.345)
% ————————
% (s-3) (s-4) (s+3) (s+4)
I googled how to add two ZPK transfer functions and it said that it’s simply linearly adding them together but Matlab is definitely doing something different (as "tf" has a zero at +/- 2.345 when neither "tf1" nor "tf2" have those zeros) zpk, add MATLAB Answers — New Questions
Planner without Teams Access
I have been using Planner via Teams for a while. Teams is going to be inaccessible for a week in order for IT to conduct some security work. Will Planner still be access via web without Teams?
I have been using Planner via Teams for a while. Teams is going to be inaccessible for a week in order for IT to conduct some security work. Will Planner still be access via web without Teams? Read More
Guest access to Team sites created without MS 365 group
Hey All,
Could someone help me understand or explain to me where I’m in the wrong?
I recently created a new site collection (Team site template) without a MS 365 group.
Since our policy says that the Sharepoint owners group permissions needs to be changed to design, this was required. I can’t (as far as I know) change these permissions on a Team site that is connected to a MS 365 group.
The issue I then had was adding access to guest accounts. I created an entra ID security group and added all the guests to it. I then gave that group contribute permissions on the Sharepoint site itself.
This however, did not work as I expected. I read that, in order for the guest accounts to have access, I need to create a Team site that IS connected to a MS 365 group.
I created the site (with ms365 group), did not add any members to any groups, but took the previously created security group and added it to the site. This did worked as intended.
I’m a bit confused on what the best practise for this situation is. We don’t want the owner group to have full control permissions. But if we want to change this, we can’t create a site that allows guests?
By default, we use the owners group to assign a Sharepoint owner to each site. This person is then used to give approvals for changes.
I don’t want to create another security group “owners” for this, because we configure access reviews on all security groups and this would just add to the amount of access reviews that the owners need to perform.
I would love to get in touch with someone who is more knowledgeable on this subject to spar a bit. I’m here to try and learn more and improve my way of working or processes/policies where possible, so all input is welcome.
I try to respond within 24 hours!
KR,
MVN
Hey All, Could someone help me understand or explain to me where I’m in the wrong? I recently created a new site collection (Team site template) without a MS 365 group. Since our policy says that the Sharepoint owners group permissions needs to be changed to design, this was required. I can’t (as far as I know) change these permissions on a Team site that is connected to a MS 365 group. The issue I then had was adding access to guest accounts. I created an entra ID security group and added all the guests to it. I then gave that group contribute permissions on the Sharepoint site itself.This however, did not work as I expected. I read that, in order for the guest accounts to have access, I need to create a Team site that IS connected to a MS 365 group. I created the site (with ms365 group), did not add any members to any groups, but took the previously created security group and added it to the site. This did worked as intended. I’m a bit confused on what the best practise for this situation is. We don’t want the owner group to have full control permissions. But if we want to change this, we can’t create a site that allows guests?By default, we use the owners group to assign a Sharepoint owner to each site. This person is then used to give approvals for changes.I don’t want to create another security group “owners” for this, because we configure access reviews on all security groups and this would just add to the amount of access reviews that the owners need to perform. I would love to get in touch with someone who is more knowledgeable on this subject to spar a bit. I’m here to try and learn more and improve my way of working or processes/policies where possible, so all input is welcome. I try to respond within 24 hours! KR,MVN Read More
Modify the dropdown content in “Link type” for Work Items.
I open a Work Item, try to add a link of another Work Item to it. When we click on Add link, and then select Existing item, in the pop-up we see a drop-down called Link type.
In the drop-down, there is a section called Remote Work.
Is it possible to edit the dropdown contents? Can I remove the whole Remote Work section and the options under it? Or is it AzDO default and cannot be modified?
If it is possible, what special role do I need in AzDO to do this?
I open a Work Item, try to add a link of another Work Item to it. When we click on Add link, and then select Existing item, in the pop-up we see a drop-down called Link type. In the drop-down, there is a section called Remote Work. Is it possible to edit the dropdown contents? Can I remove the whole Remote Work section and the options under it? Or is it AzDO default and cannot be modified? If it is possible, what special role do I need in AzDO to do this? Read More
Defender cannot scan Manifest.list images
There are more and more images that utilize the “manifest list” image format.
This format is very handsome as it allows to put multiple images (or platforms) in a single manifest file, thus reducing the complexity of having so many image tags to maintain.
Unfortunately, Azure Defender Vulnerability Management cannot scan those images.
Wouldnt it be right about time to implement this ?
There are more and more images that utilize the “manifest list” image format.This format is very handsome as it allows to put multiple images (or platforms) in a single manifest file, thus reducing the complexity of having so many image tags to maintain.Unfortunately, Azure Defender Vulnerability Management cannot scan those images. Wouldnt it be right about time to implement this ? Read More
Can using Intune and Basic Mobility and Security
Our company have License M365-E3 and E1, Current we deploy intune for all user have license M365-E3. Now We want all users with license E1 using mobile device must enroll Company portal . So we can using both Intune and Basic Mobility and Security in the same tenant ?
Our company have License M365-E3 and E1, Current we deploy intune for all user have license M365-E3. Now We want all users with license E1 using mobile device must enroll Company portal . So we can using both Intune and Basic Mobility and Security in the same tenant ? Read More
Otimização de serviços Go no Kubernetes
As configurações do ambiente execução do Go podem impactar o comportamento de um serviço em determinado ambiente.
Entender quais configurações são necessárias é imprescindível quando se trata de garantir o máximo de eficiência e desempenho de um serviço escrito em Go.
A configuração GOMAXPROCS dita o comportamento do serviço em relação ao consumo de CPU.
GOMAXPROCS: Número de “threads” disponíveis para o processo. O valor padrão é o número de núcleos da CPU.
Neste artigo, vou descrever minha experiência em busca da configuração ideal para um serviço hospedado no Kubernetes.
GOMAXPROCS e goroutines
A documentação oficial do Go refere-se às goroutines como sendo um tipo de thread mais leve. Embora correta, essa afirmação pode gerar confusões.
Uma goroutine é uma estrutura usada pelo runtime da qual conterá uma pilha de execução, onde o próprio runtime pode gerenciar sua execução. Para gerenciar a execução das rotinas, o Go implementa três componentes principais, introduzidos por Dmitry Vyukov em seu trabalho Scalable Go Scheduler Design Doc.
De forma resumida, são eles:
G (Goroutine): Contem a pilha de execução e todos artefatos necessários para execução, descrito na documentação como um tipo de thread, porém muito mais leve.
M (Thread): M é a forma mais comum de referenciar uma thread do sistema operacional.
P (Processor): Processor é uma estrutura lógica introduzida por Dmitry Vyukov para minimizar o número de goroutines que ficam em estado de espera quando uma thread M realiza uma operação bloqueante, conhecida como sys-call. O Processor implementa uma série de algoritmos que controlam a distribuição das rotinas entre as threads disponíveis. Vale lembrar que existe uma relação íntima entre um Processor P e uma Thread M, porque o P é uma estrutura lógica e, no fim do dia, vai rodar no contexto de uma Thread M.
A variável de ambiente GOMAXPROCS controla o número máximo de Processors disponíveis para nossa aplicação. Para facilitar o entendimento deste ponto, o GOMAXPROCS não controla o número máximo de Threads M disponíveis para nossa aplicação. Em outras palavras, ela não inclui o número de threads bloqueadas, realizando uma chamada para o kernel do SO.
Em outras palavras, o GOMAXPROCS controla o número máximo de threads que podem ser processadas de forma concorrente pelo processador do sistema operacional. O valor padrão é o número de núcleos do processador do host da aplicação.
Definir um valor muito alto para o GOMAXPROCS pode gerar um grande número de trocas de contexto da CPU.
GOMAXPROCS no Kubernetes
O GOMAXPROCS ainda não tem uma integração nativa com os limites definidos para um pod do Kubernetes.
Por exemplo, um pod com limite de 1 núcleo de CPU, rodando em um node com 64 núcleos de CPU, vai acabar tendo o valor padrão GOMAXPROCS=64.
A empresa Uber realizou uma série de estudos em relação aos comportamentos desse desencontro de configurações no repositório do Github: uber-go/automaxprocs.
Configurar GOMAXPROCS na definição do contêiner
Para resolver esse problema, podemos configurar a variável nas especificações do contêiner da seguinte forma:
env:
– name: GOMAXPROCS
valueFrom:
resourceFieldRef:
resource: limits.cpu
Imagine uma imagem docker, contendo a seguinte aplicação:
package main
import (
“fmt”
“runtime”
“runtime/debug”)
func main() {
fmt.Printf(“GOMAXPROCS: %dn”, runtime.GOMAXPROCS(0))
}
Podemos aplicar a configuração mencionada anteriormente na definição de um contêiner, como no exemplo abaixo:
apiVersion: v1
kind: Pod
metadata:
name: app
spec:
containers:
– name: app
image: imagem-da-aplicação
resources:
limits:
cpu: 1500m
env:
– name: GOMAXPROCS
valueFrom:
resourceFieldRef:
resource: limits.cpu
O resultado que você terá, ao conferir os logs de execução deste pod é:
GOMAXPROCS: 2
Conclusão
Entender a relação entre o número de núcleos da CPU, threads e goroutines é essencial para elevar o nível de eficiência do seu serviço Go. Este artigo pode servir de base para que você realize e aprofunde seus estudos sobre o assunto proposto, para que possa ter uma grande consciência da estratégia que pretende utilizar, mudando ou não a configuração GOMAXPROCS.
Microsoft Tech Community – Latest Blogs –Read More
fminunc limit step size
I am exploring fminunc with a 2-D but challenging function (see below), with a narrow and curved "canyon". Some times it works fine, descending to the bottom of the canyon and following it until the minimum. But at other starting points it makes a huge initial step that brings it nowhere. Isn’t there any way to limit the step size? Notice that first and second derivatives are analytic, i.e. no finite differences.
% spiralFuncion.m
% A challenging function to minimize in 2D
% JMS, Jun.2024
clear all
% Find function in a mesh
dx = 0.05;
xmax = 2.5;
x = -xmax:dx:xmax;
nx = numel(x);
[x,y] = ndgrid(x,x);
z = myfunc([x(:)’;y(:)’]);
z = reshape(z,nx,nx);
% Find minimum value at mesh points
i0 = find(z(:)==min(z(:)));
xmin = [x(i0),y(i0)]
zmin = z(i0)
% Plot function using surf and contour
figure(1)
contour(x’,y’,z’,20), axis equal
hold on, plot(xmin(1),xmin(2),’x’,’MarkerSize’,10), hold off
grid on
figure(2)
surf(x’,y’,z’)
grid on
% Set minimization options
opt = optimoptions(‘fminunc’);
opt = optimoptions(opt,’Algorithm’,’trust-region’);
opt = optimoptions(opt,’SubproblemAlgorithm’,’factorization’);
opt = optimoptions(opt,’SpecifyObjectiveGradient’,true);
opt = optimoptions(opt,’HessianFcn’,’objective’);
opt = optimoptions(opt,’MaxIterations’,1e3);
opt = optimoptions(opt,’MaxFunctionEvaluations’,1e3);
opt = optimoptions(opt,’Display’,’none’);
% Minimize function starting from a random point
x0 = randn(2,1);
[x,f,exitflag,output] = fminunc(@myfunc,x0,opt);
niter = output.iterations
fprintf(‘n%sn’,output.message)
% Find minimization path
for iter = 1:niter
opt = optimoptions(opt,’MaxIterations’,iter);
xpath(:,iter) = fminunc(@myfunc,x0,opt);
end
% opt = optimoptions(opt,’MaxIterations’,1);
% xpath(:,1) = fminunc(@myfunc,x0,opt);
% for iter = 2:niter
% xpath(:,iter) = fminunc(@myfunc,xpath(:,iter-1),opt);
% end
% Plot minimization path
figure(1)
hold on,
plot([x0(1),xpath(1,:)],[x0(2),xpath(2,:)],’r.-‘,’LineWidth’,2,’MarkerSize’,15)
plot(x(1),x(2),’.b’,’MarkerSize’,20)
hold off
%———————————
function [f,DfDx,D2fDx2] = myfunc(x)
a = 1; % smaller a => harder to minimize
r = sqrt(x(1,:).^2+x(2,:).^2);
s = atan2(x(2,:),x(1,:));
rs = 2*pi*r+s;
f = r.*exp(-a*r).*cos(rs);
% Firts derivatives
ts = x(2,:)./x(1,:); % ts=tan(s)
trs = tan(rs);
DtsDs = 1+ts.^2;
DtrsDrs = 1+trs.^2;
DsDts = 1./DtsDs;
DrsDr = 2*pi;
DrsDs = 1;
DrDx = x./r;
DtsDx = [ -x(2,:)./x(1,:).^2; 1./x(1,:) ];
DsDx = DsDts.*DtsDx;
DfDr = f./r – a*f – f.*trs.*DrsDr;
DfDs = -f.*trs.*DrsDs;
DfDx = DfDr.*DrDx + DfDs.*DsDx;
% Second derivatives
nx = size(x,2);
D2tsDs2 = 2*ts.*DtsDs;
D2trsDrs2 = 2*trs.*DtrsDrs;
D2rsDr2 = 0;
D2rsDs2 = 0;
D2rsDrDs = 0;
% note: d2x/dy2 = d(dy/dx)^-1/dy = d(dy/dx)^-1/dx * dx/dy =
% = -(dy/dx)^-2 * d2y/dx2 * (dy/dx)^-1 = -(dy/dx)^-3 * d2y/dx2
D2sDts2 = -D2tsDs2./DtsDs.^3;
D2fDr2 = DfDr./r – f./r.^2 – a*DfDr – DfDr.*trs.*DrsDr …
– f.*DtrsDrs.*DrsDr.^2 – f.*trs.*D2rsDr2;
D2fDs2 = – DfDs.*trs.*DrsDs – f.*DtrsDrs.*DrsDs.^2 …
– f.*trs.*D2rsDs2;
D2fDrDs = – DfDr.*trs.*DrsDs – f.*DtrsDrs.*DrsDr.*DrsDs …
– f.*trs.*D2rsDrDs;
for ix = 1:nx
D2rDx2 = eye(2)/r(ix) – x(:,ix).*x(:,ix)’/r(ix)^3;
D2tsDx2 = [ +2*x(2,ix)/x(1,ix).^3, -1/x(1,ix)^2
-1/x(1,ix).^2, 0 ];
D2sDx2 = D2sDts2(ix)*DtsDx(:,ix).*DtsDx(:,ix)’ + DsDts(ix)*D2tsDx2;
D2fDx2(:,:,ix) = D2fDr2(ix) *DrDx(:,ix).*DrDx(:,ix)’ …
+ D2fDs2(ix) *DsDx(:,ix).*DsDx(:,ix)’ …
+ D2fDrDs(ix)*DrDx(:,ix).*DsDx(:,ix)’ …
+ D2fDrDs(ix)*DsDx(:,ix).*DrDx(:,ix)’ …
+ DfDr(ix)*D2rDx2 + DfDs(ix)*D2sDx2;
end
endI am exploring fminunc with a 2-D but challenging function (see below), with a narrow and curved "canyon". Some times it works fine, descending to the bottom of the canyon and following it until the minimum. But at other starting points it makes a huge initial step that brings it nowhere. Isn’t there any way to limit the step size? Notice that first and second derivatives are analytic, i.e. no finite differences.
% spiralFuncion.m
% A challenging function to minimize in 2D
% JMS, Jun.2024
clear all
% Find function in a mesh
dx = 0.05;
xmax = 2.5;
x = -xmax:dx:xmax;
nx = numel(x);
[x,y] = ndgrid(x,x);
z = myfunc([x(:)’;y(:)’]);
z = reshape(z,nx,nx);
% Find minimum value at mesh points
i0 = find(z(:)==min(z(:)));
xmin = [x(i0),y(i0)]
zmin = z(i0)
% Plot function using surf and contour
figure(1)
contour(x’,y’,z’,20), axis equal
hold on, plot(xmin(1),xmin(2),’x’,’MarkerSize’,10), hold off
grid on
figure(2)
surf(x’,y’,z’)
grid on
% Set minimization options
opt = optimoptions(‘fminunc’);
opt = optimoptions(opt,’Algorithm’,’trust-region’);
opt = optimoptions(opt,’SubproblemAlgorithm’,’factorization’);
opt = optimoptions(opt,’SpecifyObjectiveGradient’,true);
opt = optimoptions(opt,’HessianFcn’,’objective’);
opt = optimoptions(opt,’MaxIterations’,1e3);
opt = optimoptions(opt,’MaxFunctionEvaluations’,1e3);
opt = optimoptions(opt,’Display’,’none’);
% Minimize function starting from a random point
x0 = randn(2,1);
[x,f,exitflag,output] = fminunc(@myfunc,x0,opt);
niter = output.iterations
fprintf(‘n%sn’,output.message)
% Find minimization path
for iter = 1:niter
opt = optimoptions(opt,’MaxIterations’,iter);
xpath(:,iter) = fminunc(@myfunc,x0,opt);
end
% opt = optimoptions(opt,’MaxIterations’,1);
% xpath(:,1) = fminunc(@myfunc,x0,opt);
% for iter = 2:niter
% xpath(:,iter) = fminunc(@myfunc,xpath(:,iter-1),opt);
% end
% Plot minimization path
figure(1)
hold on,
plot([x0(1),xpath(1,:)],[x0(2),xpath(2,:)],’r.-‘,’LineWidth’,2,’MarkerSize’,15)
plot(x(1),x(2),’.b’,’MarkerSize’,20)
hold off
%———————————
function [f,DfDx,D2fDx2] = myfunc(x)
a = 1; % smaller a => harder to minimize
r = sqrt(x(1,:).^2+x(2,:).^2);
s = atan2(x(2,:),x(1,:));
rs = 2*pi*r+s;
f = r.*exp(-a*r).*cos(rs);
% Firts derivatives
ts = x(2,:)./x(1,:); % ts=tan(s)
trs = tan(rs);
DtsDs = 1+ts.^2;
DtrsDrs = 1+trs.^2;
DsDts = 1./DtsDs;
DrsDr = 2*pi;
DrsDs = 1;
DrDx = x./r;
DtsDx = [ -x(2,:)./x(1,:).^2; 1./x(1,:) ];
DsDx = DsDts.*DtsDx;
DfDr = f./r – a*f – f.*trs.*DrsDr;
DfDs = -f.*trs.*DrsDs;
DfDx = DfDr.*DrDx + DfDs.*DsDx;
% Second derivatives
nx = size(x,2);
D2tsDs2 = 2*ts.*DtsDs;
D2trsDrs2 = 2*trs.*DtrsDrs;
D2rsDr2 = 0;
D2rsDs2 = 0;
D2rsDrDs = 0;
% note: d2x/dy2 = d(dy/dx)^-1/dy = d(dy/dx)^-1/dx * dx/dy =
% = -(dy/dx)^-2 * d2y/dx2 * (dy/dx)^-1 = -(dy/dx)^-3 * d2y/dx2
D2sDts2 = -D2tsDs2./DtsDs.^3;
D2fDr2 = DfDr./r – f./r.^2 – a*DfDr – DfDr.*trs.*DrsDr …
– f.*DtrsDrs.*DrsDr.^2 – f.*trs.*D2rsDr2;
D2fDs2 = – DfDs.*trs.*DrsDs – f.*DtrsDrs.*DrsDs.^2 …
– f.*trs.*D2rsDs2;
D2fDrDs = – DfDr.*trs.*DrsDs – f.*DtrsDrs.*DrsDr.*DrsDs …
– f.*trs.*D2rsDrDs;
for ix = 1:nx
D2rDx2 = eye(2)/r(ix) – x(:,ix).*x(:,ix)’/r(ix)^3;
D2tsDx2 = [ +2*x(2,ix)/x(1,ix).^3, -1/x(1,ix)^2
-1/x(1,ix).^2, 0 ];
D2sDx2 = D2sDts2(ix)*DtsDx(:,ix).*DtsDx(:,ix)’ + DsDts(ix)*D2tsDx2;
D2fDx2(:,:,ix) = D2fDr2(ix) *DrDx(:,ix).*DrDx(:,ix)’ …
+ D2fDs2(ix) *DsDx(:,ix).*DsDx(:,ix)’ …
+ D2fDrDs(ix)*DrDx(:,ix).*DsDx(:,ix)’ …
+ D2fDrDs(ix)*DsDx(:,ix).*DrDx(:,ix)’ …
+ DfDr(ix)*D2rDx2 + DfDs(ix)*D2sDx2;
end
end I am exploring fminunc with a 2-D but challenging function (see below), with a narrow and curved "canyon". Some times it works fine, descending to the bottom of the canyon and following it until the minimum. But at other starting points it makes a huge initial step that brings it nowhere. Isn’t there any way to limit the step size? Notice that first and second derivatives are analytic, i.e. no finite differences.
% spiralFuncion.m
% A challenging function to minimize in 2D
% JMS, Jun.2024
clear all
% Find function in a mesh
dx = 0.05;
xmax = 2.5;
x = -xmax:dx:xmax;
nx = numel(x);
[x,y] = ndgrid(x,x);
z = myfunc([x(:)’;y(:)’]);
z = reshape(z,nx,nx);
% Find minimum value at mesh points
i0 = find(z(:)==min(z(:)));
xmin = [x(i0),y(i0)]
zmin = z(i0)
% Plot function using surf and contour
figure(1)
contour(x’,y’,z’,20), axis equal
hold on, plot(xmin(1),xmin(2),’x’,’MarkerSize’,10), hold off
grid on
figure(2)
surf(x’,y’,z’)
grid on
% Set minimization options
opt = optimoptions(‘fminunc’);
opt = optimoptions(opt,’Algorithm’,’trust-region’);
opt = optimoptions(opt,’SubproblemAlgorithm’,’factorization’);
opt = optimoptions(opt,’SpecifyObjectiveGradient’,true);
opt = optimoptions(opt,’HessianFcn’,’objective’);
opt = optimoptions(opt,’MaxIterations’,1e3);
opt = optimoptions(opt,’MaxFunctionEvaluations’,1e3);
opt = optimoptions(opt,’Display’,’none’);
% Minimize function starting from a random point
x0 = randn(2,1);
[x,f,exitflag,output] = fminunc(@myfunc,x0,opt);
niter = output.iterations
fprintf(‘n%sn’,output.message)
% Find minimization path
for iter = 1:niter
opt = optimoptions(opt,’MaxIterations’,iter);
xpath(:,iter) = fminunc(@myfunc,x0,opt);
end
% opt = optimoptions(opt,’MaxIterations’,1);
% xpath(:,1) = fminunc(@myfunc,x0,opt);
% for iter = 2:niter
% xpath(:,iter) = fminunc(@myfunc,xpath(:,iter-1),opt);
% end
% Plot minimization path
figure(1)
hold on,
plot([x0(1),xpath(1,:)],[x0(2),xpath(2,:)],’r.-‘,’LineWidth’,2,’MarkerSize’,15)
plot(x(1),x(2),’.b’,’MarkerSize’,20)
hold off
%———————————
function [f,DfDx,D2fDx2] = myfunc(x)
a = 1; % smaller a => harder to minimize
r = sqrt(x(1,:).^2+x(2,:).^2);
s = atan2(x(2,:),x(1,:));
rs = 2*pi*r+s;
f = r.*exp(-a*r).*cos(rs);
% Firts derivatives
ts = x(2,:)./x(1,:); % ts=tan(s)
trs = tan(rs);
DtsDs = 1+ts.^2;
DtrsDrs = 1+trs.^2;
DsDts = 1./DtsDs;
DrsDr = 2*pi;
DrsDs = 1;
DrDx = x./r;
DtsDx = [ -x(2,:)./x(1,:).^2; 1./x(1,:) ];
DsDx = DsDts.*DtsDx;
DfDr = f./r – a*f – f.*trs.*DrsDr;
DfDs = -f.*trs.*DrsDs;
DfDx = DfDr.*DrDx + DfDs.*DsDx;
% Second derivatives
nx = size(x,2);
D2tsDs2 = 2*ts.*DtsDs;
D2trsDrs2 = 2*trs.*DtrsDrs;
D2rsDr2 = 0;
D2rsDs2 = 0;
D2rsDrDs = 0;
% note: d2x/dy2 = d(dy/dx)^-1/dy = d(dy/dx)^-1/dx * dx/dy =
% = -(dy/dx)^-2 * d2y/dx2 * (dy/dx)^-1 = -(dy/dx)^-3 * d2y/dx2
D2sDts2 = -D2tsDs2./DtsDs.^3;
D2fDr2 = DfDr./r – f./r.^2 – a*DfDr – DfDr.*trs.*DrsDr …
– f.*DtrsDrs.*DrsDr.^2 – f.*trs.*D2rsDr2;
D2fDs2 = – DfDs.*trs.*DrsDs – f.*DtrsDrs.*DrsDs.^2 …
– f.*trs.*D2rsDs2;
D2fDrDs = – DfDr.*trs.*DrsDs – f.*DtrsDrs.*DrsDr.*DrsDs …
– f.*trs.*D2rsDrDs;
for ix = 1:nx
D2rDx2 = eye(2)/r(ix) – x(:,ix).*x(:,ix)’/r(ix)^3;
D2tsDx2 = [ +2*x(2,ix)/x(1,ix).^3, -1/x(1,ix)^2
-1/x(1,ix).^2, 0 ];
D2sDx2 = D2sDts2(ix)*DtsDx(:,ix).*DtsDx(:,ix)’ + DsDts(ix)*D2tsDx2;
D2fDx2(:,:,ix) = D2fDr2(ix) *DrDx(:,ix).*DrDx(:,ix)’ …
+ D2fDs2(ix) *DsDx(:,ix).*DsDx(:,ix)’ …
+ D2fDrDs(ix)*DrDx(:,ix).*DsDx(:,ix)’ …
+ D2fDrDs(ix)*DsDx(:,ix).*DrDx(:,ix)’ …
+ DfDr(ix)*D2rDx2 + DfDs(ix)*D2sDx2;
end
end fminunc, step size MATLAB Answers — New Questions
How to use ‘goto’ statement?
I have the problem in the code segment:
if matchedRulesCount==0
goto(‘N’)
return
else
goto(‘N1’)
return
end
fprintf(‘Number of rules matched are:%dn’,matchedRulesCount);
%LABEL N
disp(‘No rule is fired.’);
%LABEL N1
choice=input(‘Do yo want to try once more? n0. For No.n1. For yes. n’);
I get the following error
??? Undefined function or method ‘goto’ for input arguments of type ‘char’.I have the problem in the code segment:
if matchedRulesCount==0
goto(‘N’)
return
else
goto(‘N1’)
return
end
fprintf(‘Number of rules matched are:%dn’,matchedRulesCount);
%LABEL N
disp(‘No rule is fired.’);
%LABEL N1
choice=input(‘Do yo want to try once more? n0. For No.n1. For yes. n’);
I get the following error
??? Undefined function or method ‘goto’ for input arguments of type ‘char’. I have the problem in the code segment:
if matchedRulesCount==0
goto(‘N’)
return
else
goto(‘N1’)
return
end
fprintf(‘Number of rules matched are:%dn’,matchedRulesCount);
%LABEL N
disp(‘No rule is fired.’);
%LABEL N1
choice=input(‘Do yo want to try once more? n0. For No.n1. For yes. n’);
I get the following error
??? Undefined function or method ‘goto’ for input arguments of type ‘char’. goto statement MATLAB Answers — New Questions
Uistack with a Graph and Subgraphs (GraphPlot)
Introduction. I have the following Graph and Subgraphs:
% Graph
s = [1 1 1 3 3 6 7 8 9 10 4 12 13 5 15 16 17 18 19 19 20 20 17 24 25 4 27 28 29];
t = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
G = graph(s,t);
% Node ID: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
G.Nodes.X = [2 1 3 2 4 4 5 4 5 4 5 1 3 3 5 6 7 6 8 7 9 8 9 8 9 10 1 1 0 1]’;
G.Nodes.Y = [2 1 3 9 3 5 8 12 13 18 21 15 18 21 0 2 8 12 15 20 10 22 18 5 4 4 5 8 12 23]’;
% Subgraphs
Gpath{1} = subgraph(G,shortestpath(G,4,14));
Gpath{2} = subgraph(G,shortestpath(G,4,26));
Gpath{3} = subgraph(G,shortestpath(G,4,30));
Gpath{4} = subgraph(G,shortestpath(G,3,10));
Gpath{5} = subgraph(G,shortestpath(G,3,28));
Gpath{6} = subgraph(G,shortestpath(G,3,21));
Gpath{7} = subgraph(G,shortestpath(G,17,12));
Gpath{8} = subgraph(G,shortestpath(G,17,23));
Gpath{9} = subgraph(G,shortestpath(G,17,26));
% Figure
hold on
p(1) = plot(G,’XData’,G.Nodes.X,’YData’,G.Nodes.Y,’LineWidth’,1,’EdgeColor’,’k’,’NodeColor’,’k’);
for i = [1 2 3]
p(2) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’y’,’NodeColor’,’y’);
p(2).NodeLabel = {};
p(2).EdgeAlpha = 1;
p(2).LineWidth = 5;
end
for i = [7 8 9]
p(3) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’g’,’NodeColor’,’g’);
p(3).NodeLabel = {};
p(3).EdgeAlpha = 1;
p(3).LineWidth = 9;
p(3).DisplayName = ‘Apple’;
end
for i = [4 5 6]
p(4) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’r’,’NodeColor’,’r’);
p(4).NodeLabel = {};
p(4).EdgeAlpha = 1;
p(4).LineWidth = 15;
p(4).DisplayName = ‘Strawberry’;
end
legend(p)
Just for clarity and a better understanding, here below I plot the GraphPlots separately as well:
Problem. When I try the to use uistack to change the visual stacking of the 4 GraphPlots, by bringing to the bottom both the GraphPlots called "Apple" (in green) and "Strawberry" (in red),
% Select the GraphPlots which have a non-empty "DisplayName", i.e. "Apple"
% and "Strawberry", and use Uistack
idx = find(~cellfun(@isempty,{p.DisplayName}));
p2 = uistack(p(idx),’bottom’)
legend(p2)
Only some Subgraphs are reshuffled, which means, to the best of my understanding, that uistack does not act on the 4 GraphPlots of "p", but, instead, on the 10 GraphPlots of "p2", i.e on the single Subgraphs:
Question. How to get what I expect, i.e. the following plot, where the 4 GraphPlots of "p" are reshuffled:
Note. Also, I have noticed that "p" and the "uistacked p", i.e. "p2", have different dimensions, and I guess it is the source of the problem:
p =
1×4 GraphPlot array:
GraphPlot GraphPlot GraphPlot GraphPlot
p2 =
10×1 GraphPlot array:
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlotIntroduction. I have the following Graph and Subgraphs:
% Graph
s = [1 1 1 3 3 6 7 8 9 10 4 12 13 5 15 16 17 18 19 19 20 20 17 24 25 4 27 28 29];
t = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
G = graph(s,t);
% Node ID: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
G.Nodes.X = [2 1 3 2 4 4 5 4 5 4 5 1 3 3 5 6 7 6 8 7 9 8 9 8 9 10 1 1 0 1]’;
G.Nodes.Y = [2 1 3 9 3 5 8 12 13 18 21 15 18 21 0 2 8 12 15 20 10 22 18 5 4 4 5 8 12 23]’;
% Subgraphs
Gpath{1} = subgraph(G,shortestpath(G,4,14));
Gpath{2} = subgraph(G,shortestpath(G,4,26));
Gpath{3} = subgraph(G,shortestpath(G,4,30));
Gpath{4} = subgraph(G,shortestpath(G,3,10));
Gpath{5} = subgraph(G,shortestpath(G,3,28));
Gpath{6} = subgraph(G,shortestpath(G,3,21));
Gpath{7} = subgraph(G,shortestpath(G,17,12));
Gpath{8} = subgraph(G,shortestpath(G,17,23));
Gpath{9} = subgraph(G,shortestpath(G,17,26));
% Figure
hold on
p(1) = plot(G,’XData’,G.Nodes.X,’YData’,G.Nodes.Y,’LineWidth’,1,’EdgeColor’,’k’,’NodeColor’,’k’);
for i = [1 2 3]
p(2) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’y’,’NodeColor’,’y’);
p(2).NodeLabel = {};
p(2).EdgeAlpha = 1;
p(2).LineWidth = 5;
end
for i = [7 8 9]
p(3) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’g’,’NodeColor’,’g’);
p(3).NodeLabel = {};
p(3).EdgeAlpha = 1;
p(3).LineWidth = 9;
p(3).DisplayName = ‘Apple’;
end
for i = [4 5 6]
p(4) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’r’,’NodeColor’,’r’);
p(4).NodeLabel = {};
p(4).EdgeAlpha = 1;
p(4).LineWidth = 15;
p(4).DisplayName = ‘Strawberry’;
end
legend(p)
Just for clarity and a better understanding, here below I plot the GraphPlots separately as well:
Problem. When I try the to use uistack to change the visual stacking of the 4 GraphPlots, by bringing to the bottom both the GraphPlots called "Apple" (in green) and "Strawberry" (in red),
% Select the GraphPlots which have a non-empty "DisplayName", i.e. "Apple"
% and "Strawberry", and use Uistack
idx = find(~cellfun(@isempty,{p.DisplayName}));
p2 = uistack(p(idx),’bottom’)
legend(p2)
Only some Subgraphs are reshuffled, which means, to the best of my understanding, that uistack does not act on the 4 GraphPlots of "p", but, instead, on the 10 GraphPlots of "p2", i.e on the single Subgraphs:
Question. How to get what I expect, i.e. the following plot, where the 4 GraphPlots of "p" are reshuffled:
Note. Also, I have noticed that "p" and the "uistacked p", i.e. "p2", have different dimensions, and I guess it is the source of the problem:
p =
1×4 GraphPlot array:
GraphPlot GraphPlot GraphPlot GraphPlot
p2 =
10×1 GraphPlot array:
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot Introduction. I have the following Graph and Subgraphs:
% Graph
s = [1 1 1 3 3 6 7 8 9 10 4 12 13 5 15 16 17 18 19 19 20 20 17 24 25 4 27 28 29];
t = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30];
G = graph(s,t);
% Node ID: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
G.Nodes.X = [2 1 3 2 4 4 5 4 5 4 5 1 3 3 5 6 7 6 8 7 9 8 9 8 9 10 1 1 0 1]’;
G.Nodes.Y = [2 1 3 9 3 5 8 12 13 18 21 15 18 21 0 2 8 12 15 20 10 22 18 5 4 4 5 8 12 23]’;
% Subgraphs
Gpath{1} = subgraph(G,shortestpath(G,4,14));
Gpath{2} = subgraph(G,shortestpath(G,4,26));
Gpath{3} = subgraph(G,shortestpath(G,4,30));
Gpath{4} = subgraph(G,shortestpath(G,3,10));
Gpath{5} = subgraph(G,shortestpath(G,3,28));
Gpath{6} = subgraph(G,shortestpath(G,3,21));
Gpath{7} = subgraph(G,shortestpath(G,17,12));
Gpath{8} = subgraph(G,shortestpath(G,17,23));
Gpath{9} = subgraph(G,shortestpath(G,17,26));
% Figure
hold on
p(1) = plot(G,’XData’,G.Nodes.X,’YData’,G.Nodes.Y,’LineWidth’,1,’EdgeColor’,’k’,’NodeColor’,’k’);
for i = [1 2 3]
p(2) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’y’,’NodeColor’,’y’);
p(2).NodeLabel = {};
p(2).EdgeAlpha = 1;
p(2).LineWidth = 5;
end
for i = [7 8 9]
p(3) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’g’,’NodeColor’,’g’);
p(3).NodeLabel = {};
p(3).EdgeAlpha = 1;
p(3).LineWidth = 9;
p(3).DisplayName = ‘Apple’;
end
for i = [4 5 6]
p(4) = plot(Gpath{i},’XData’,Gpath{i}.Nodes.X,’YData’,Gpath{i}.Nodes.Y,’EdgeColor’,’r’,’NodeColor’,’r’);
p(4).NodeLabel = {};
p(4).EdgeAlpha = 1;
p(4).LineWidth = 15;
p(4).DisplayName = ‘Strawberry’;
end
legend(p)
Just for clarity and a better understanding, here below I plot the GraphPlots separately as well:
Problem. When I try the to use uistack to change the visual stacking of the 4 GraphPlots, by bringing to the bottom both the GraphPlots called "Apple" (in green) and "Strawberry" (in red),
% Select the GraphPlots which have a non-empty "DisplayName", i.e. "Apple"
% and "Strawberry", and use Uistack
idx = find(~cellfun(@isempty,{p.DisplayName}));
p2 = uistack(p(idx),’bottom’)
legend(p2)
Only some Subgraphs are reshuffled, which means, to the best of my understanding, that uistack does not act on the 4 GraphPlots of "p", but, instead, on the 10 GraphPlots of "p2", i.e on the single Subgraphs:
Question. How to get what I expect, i.e. the following plot, where the 4 GraphPlots of "p" are reshuffled:
Note. Also, I have noticed that "p" and the "uistacked p", i.e. "p2", have different dimensions, and I guess it is the source of the problem:
p =
1×4 GraphPlot array:
GraphPlot GraphPlot GraphPlot GraphPlot
p2 =
10×1 GraphPlot array:
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot
GraphPlot uistack, graph, subgraph, graphplot, visual stack MATLAB Answers — New Questions
Phase retrieval of a periodic signal, not working well
Hello,
I am trying solve something I thought would be straigfoward, but is not so far ^^.
Let assume we have a perriodic signal as such:
x=0:400;
T=39.5;
PhiO=0.43;
y=5+cos((2*pi/T).*x+PhiO);
And the aim is to get the phase and period of this signal.
Here is for the code for the period retriaval:
%period
[pks,locs] = findpeaks(y,’MinPeakDistance’,20) ;
Px_av=mean(diff(locs));
Here is the code for the phase retrieval:
h=fft(y);
plot(abs(h)) % the eleventh element is the frequency of my signal so the eleventh element of the phase "angle(h)" should be the phase of my signal. But if I plot the original signal and the retrieved one, it doesn’t match well:
Phi=angle(h);
plot(x,max(y).*cos((2*pi/Px_av).*x+Phi(1,11)));hold on;plot(x,y)
Given that PhiO and Px_av are different, I tried to use interp Phi to match the right frequency, but it doesn’t work either.
Do you understand what I do wrong, please ?Hello,
I am trying solve something I thought would be straigfoward, but is not so far ^^.
Let assume we have a perriodic signal as such:
x=0:400;
T=39.5;
PhiO=0.43;
y=5+cos((2*pi/T).*x+PhiO);
And the aim is to get the phase and period of this signal.
Here is for the code for the period retriaval:
%period
[pks,locs] = findpeaks(y,’MinPeakDistance’,20) ;
Px_av=mean(diff(locs));
Here is the code for the phase retrieval:
h=fft(y);
plot(abs(h)) % the eleventh element is the frequency of my signal so the eleventh element of the phase "angle(h)" should be the phase of my signal. But if I plot the original signal and the retrieved one, it doesn’t match well:
Phi=angle(h);
plot(x,max(y).*cos((2*pi/Px_av).*x+Phi(1,11)));hold on;plot(x,y)
Given that PhiO and Px_av are different, I tried to use interp Phi to match the right frequency, but it doesn’t work either.
Do you understand what I do wrong, please ? Hello,
I am trying solve something I thought would be straigfoward, but is not so far ^^.
Let assume we have a perriodic signal as such:
x=0:400;
T=39.5;
PhiO=0.43;
y=5+cos((2*pi/T).*x+PhiO);
And the aim is to get the phase and period of this signal.
Here is for the code for the period retriaval:
%period
[pks,locs] = findpeaks(y,’MinPeakDistance’,20) ;
Px_av=mean(diff(locs));
Here is the code for the phase retrieval:
h=fft(y);
plot(abs(h)) % the eleventh element is the frequency of my signal so the eleventh element of the phase "angle(h)" should be the phase of my signal. But if I plot the original signal and the retrieved one, it doesn’t match well:
Phi=angle(h);
plot(x,max(y).*cos((2*pi/Px_av).*x+Phi(1,11)));hold on;plot(x,y)
Given that PhiO and Px_av are different, I tried to use interp Phi to match the right frequency, but it doesn’t work either.
Do you understand what I do wrong, please ? phase retrieval, matlab, fft MATLAB Answers — New Questions
Soluções da Microsoft para as organizações sociais – via Techsoup
Olá Pessoal,
tenho o prazer em compartilhar a apresentação da Techsoup no evento AI for ChangeMakers.
Nela vocês encontrarão as principais informações sobre as soluções da Microsoft para as organizações sociais, através da Techsoup.
Olá Pessoal, tenho o prazer em compartilhar a apresentação da Techsoup no evento AI for ChangeMakers.Nela vocês encontrarão as principais informações sobre as soluções da Microsoft para as organizações sociais, através da Techsoup. Read More
Display negative value in a column if a condition is meet in another column
Hello all,
Can you please help me? I have 1 column named Sales Activity that has several selection options and the other column MF/Line (ALL). When the user select in the Sales Activiy the condition Disconnecion the value in M.fee tab to be negative.
Thank you!
Hello all, Can you please help me? I have 1 column named Sales Activity that has several selection options and the other column MF/Line (ALL). When the user select in the Sales Activiy the condition Disconnecion the value in M.fee tab to be negative. Thank you! Read More