Assign a line in every element of a 3d matrix
Show older comments
I have a 10x10x10 matrix that looks like the below attached.I want to add a line 101.543 30.453 50.185 to the ement that contains 10.

7 Comments
James Tursa
on 14 Oct 2022
Please provide more detail. What would the desired outcome be for your example?
MD MAHABUBUR ROHOMAN
on 14 Oct 2022
the cyclist
on 14 Oct 2022
This is still not clear. What do you mean by changed with 101.543 AND 30.453 AND 50.185?
Your picture shows only 101.543.
MD MAHABUBUR ROHOMAN
on 14 Oct 2022
James Tursa
on 14 Oct 2022
Edited: James Tursa
on 14 Oct 2022
@MD MAHABUBUR ROHOMAN Please post the exact result you want for your example. Not just scribblings on top of the input. We can't help you if we don't know what you want.
MD MAHABUBUR ROHOMAN
on 14 Oct 2022
James Tursa
on 18 Oct 2022
@MD MAHABUBUR ROHOMAN If you can't describe to us the specific output you want, how can we possibly know what you need?
Answers (2)
the cyclist
on 14 Oct 2022
To replace all values of 10 with 101.543, you can do
val(val==10) = 101.543;
Maybe that helps?
If we look at the array you posted, what I think you want would involve the first row of page 1 of val having 10 elements and row 2 having 12 or 13 (depending on whether your three elements were inserted in place of 10 or after.) In either of those cases, that is not possible. All rows in an array in MATLAB must have the same number of columns.
But if that's not what you want, let's take a smaller example. Please show us exactly what you'd want as a result if you did your replacement on this (much smaller) matrix and tell us exactly how you got from the A matrix to that result.
A = [1 2 3; 4 10 6]
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!