# How do you write this "| "symbol in MATLAB?

15 vues (au cours des 30 derniers jours)
Matthew Worker le 28 Nov 2021
Modifié(e) : John Kelly le 8 Déc 2021
How i would write that symbol in MATLAB?
i left it out and even tried'/'
but i keep getting warnings within the script
thank u!
will attach my code too
if ((floor(mr/2)==ceil(mr/2))(floor(mc/2)==ceil(mc/2)))
then error('The mask must have odd dimensions.')
end
[r,c]=size (image);
nr=(mr-1)/2;
nc=(mc-1)/2;
image2=zeros(r+mr-1, C+mc-1);
image2(nr+1:r+nr, nc+1:c+nc)=image;
image2(image2==0) =Inf;
image2(image2==1) =0;
for i=nr+1:r+nr
for j=nc+1 : c+nc
end
end
for i=r+nr:-1:nr+1
for j=c+nc:-1:nc+1
end
end
res=image2(nr+1:r+nr,nc+1:c+nc);
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
Rena Berman le 8 Déc 2021

Connectez-vous pour commenter.

### Réponse acceptée

DGM le 28 Nov 2021
The expression
((floor(mr/2)==ceil(mr/2)) | (floor(mc/2)==ceil(mc/2)))
conceptually says
((number of rows is even) OR (number of columns is even))
Which is a peculiar way to do the test, but it should work fine.
That said, there are two OR operators:
| is a general elementwise logical OR that can be used on arrays
|| is the logical OR with short-circuit functionality. This is potentially more efficient, but only works with scalar logical arguments
In this case, you could use either, but using || would be preferred.
If MLINT was putting a squiggle under the lone |, that was probably why. It's not an error. It's just a hint.
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Plus de réponses (1)

Steven Lord le 28 Nov 2021
If for whatever reason you cannot type the | character (which on my QWERTY keyboard is Shift plus the key to the far right of the second row of keys) you could call the function form of that operator using the or function.
x = 2;
if (x < 1) | (x > 3)
disp('Out of bounds')
else
disp('In bounds')
end
In bounds
if or(x < 1, x > 3)
disp('Out of bounds')
else
disp('In bounds')
end
In bounds
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

R2021a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by