how to add the first row all the odd columns by step of 2 odd columns
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
0 votes
I want to add 1 and 3 the 2 and 1. Then moving to second row I want to add 1 and 1 then 4 and 5. Similarly I want to, in general, using using loop for an image
a = [...
1 2 3 1
1 4 1 5
5 8 5 9
1 9 2 1]
2 Comments
madhan ravi
on 1 Sep 2018
What’s your required output ? Can you give an example?
juveria fatima
on 1 Sep 2018
i want to add first column with third ,then fifth column to be added with seventh in short (i want to add all the odd columns) then even columns to added
Accepted Answer
madhan ravi
on 1 Sep 2018
Edited: madhan ravi
on 1 Sep 2018
Try this:
a1=a(:,1:2:end) %for odd columns
a2=a(:,2:2:end) %for even columns
oddcolumns=sum(a1,2)
evencolumns=sum(a2,2)
a
15 Comments
madhan ravi
on 1 Sep 2018
If it’s not upto the expectations let me know.
juveria fatima
on 1 Sep 2018
i have to solve two problems to explain my problem clearly i made a slide kindly review
madhan ravi
on 1 Sep 2018
The updated code gives you the result as expected now.
juveria fatima
on 1 Sep 2018
as per results evencolumn sum should be
3
9
17
10
a =
1 3
1 1
5 5
1 2
a1 =
3
1
5
2
oddcolumns =
4
2
10
3
evencolumns =
3
1
5
2
madhan ravi
on 1 Sep 2018
That’s the result I’m getting.
madhan ravi
on 1 Sep 2018
a =
1 2 3 1
1 4 1 5
5 8 5 9
1 9 2 1
a1 =
1 3
1 1
5 5
1 2
a2 =
2 1
4 5
8 9
9 1
oddcolumns =
4
2
10
3
evencolumns =
3
9
17
10
>>
juveria fatima
on 1 Sep 2018
thank you i got it
madhan ravi
on 1 Sep 2018
did you check the code which was updated?
juveria fatima
on 1 Sep 2018
can you please help me out with second binary image example in above pdf attached
madhan ravi
on 1 Sep 2018
Sorry I have no experience with that unfortunately
juveria fatima
on 1 Sep 2018
ok can you do the inverse of the above updated code i want to get the matrix a back
madhan ravi
on 1 Sep 2018
Edited: madhan ravi
on 1 Sep 2018
Like can you type the required result and post it here? So that I could understand what should be done?
juveria fatima
on 1 Sep 2018
from the obtained result
oddcolumns =
4
2
10
3
evencolumns =
3
9
17
10
i want to get back the input a i.e
a =
1 2 3 1
1 4 1 5
5 8 5 9
1 9 2 1
madhan ravi
on 1 Sep 2018
Check the updated code.
juveria fatima
on 1 Sep 2018
consider this as encoding code where a is encoded as odd columns and even columns
a=[1 2 3 1;1 4 1 5;5 8 5 9;1 9 2 1]
a1=a(:,1:2:end) %for odd columns
a2=a(:,2:2:end) %for even columns
oddcolumns=sum(a1,2)
evencolumns=sum(a2,2)
now i want its inverse i.e decoding back to a ( output should be a )
More Answers (0)
Categories
Find more on Image Arithmetic in Help Center and File Exchange
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)