How to write this code in matlab?

  • Context: MATLAB 
  • Thread starter Thread starter vikky_manit
  • Start date Start date
  • Tags Tags
    Code Matlab
Click For Summary

Discussion Overview

The discussion revolves around a MATLAB coding issue where a user is attempting to compute values in a matrix based on conditions applied to another matrix, specifically related to pixel values of an image. The focus is on debugging the code to achieve the desired output.

Discussion Character

  • Technical explanation

Main Points Raised

  • The user reports that their code is not functioning as expected, resulting in all values of G being 100.
  • Another participant questions the definition and content of the matrix temp(i,j) to clarify the issue.
  • A further inquiry is made about the expected output of the code, suggesting a need for more context on the user's goals.
  • The user clarifies that temp(i,j) contains pixel values of an image, which is crucial for understanding the code's purpose.

Areas of Agreement / Disagreement

Participants are seeking clarification on the variables and expected outputs, indicating that the discussion is still unresolved and lacks consensus on the correct implementation.

Contextual Notes

There are missing definitions for variables such as M and V, which may affect the understanding of the code's functionality. Additionally, the assumptions about the structure and content of the temp matrix are not fully explored.

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 ·
Replies
4
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 11 ·
Replies
11
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K