MATLAB How to write this code in matlab?

  • Thread starter Thread starter vikky_manit
  • Start date Start date
  • Tags Tags
    Code Matlab
AI Thread Summary
The discussion revolves around a MATLAB code snippet intended to compute values for matrix G based on conditions applied to another matrix, temp. The user is encountering an issue where all values in G are returning as 100, indicating a problem with the conditional logic or the calculations. The matrix temp is described as containing pixel values from an image, but the variable M is not defined in the provided code, leading to confusion. Participants in the discussion are seeking clarification on the expected output, the definition of M, and potential corrections to the code to achieve the desired results. The need for proper initialization and understanding of matrix operations in MATLAB is emphasized for troubleshooting the issue.
vikky_manit
Messages
3
Reaction score
0
M0=100;
var0=100;

i=1:478
j=1:448
if(temp(i,j)>M)
G(i,j)=M0+sqrt(double((var0*power((temp(i,j)-M),2))/V));
else

G(i,j)=M0-sqrt(double((var0*power((temp(i,j)-M),2))/V));

Where temp(i,j) is an matrix. This code is not working. I am getting the values of G as 100. Please help me with the correct code. I am new to matlab.
 
Physics news on Phys.org
What is temp()? What is your expected output?

In code tags:
Code:
M0=100;
var0=100;

i[/color]=1:478;
j[/color]=1:448;
[b]if[/b][/color](temp(i[/color],j[/color])>[/color]M)
    G(i[/color],j[/color])=M0+[/color]sqrt[/color](double((var0*[/color]power((temp(i[/color],j[/color])-[/color]M),2))/[/color]V));
[b]else[/b][/color]
    G(i[/color],j[/color])=M0-[/color]sqrt[/color](double((var0*[/color]power((temp(i[/color],j[/color])-[/color]M),2))/[/color]V));
[b]end[/b][/color]
 
temp(i,j) is an matrix containing pixel values of an image.
 

Similar threads

Replies
4
Views
4K
Replies
7
Views
2K
Replies
5
Views
3K
Replies
11
Views
4K
Replies
2
Views
3K
Replies
2
Views
2K
Back
Top