i have a 2d matrices and i am visualizing them using imagesc; (x vector is time) and the x vector is [1 200] i wand to rescale it to be [-1.4 2.4] and visualizing them new time vector. How to do so?

 Réponse acceptée

Voss
Voss le 29 Jan 2022
If I understand correctly, here's how you can rescale a matrix to be from -1.4 to 2.4 instead of from 1 to 200:
A = reshape(1:200,10,20); % a 2D matrix with values from 1 to 200
x = [1 200];
new_x = [-1.4 2.4];
new_A = (A-x(1))./(x(2)-x(1)).*(new_x(2)-new_x(1))+new_x(1);
disp(A); disp(new_A);
1 11 21 31 41 51 61 71 81 91 101 111 121 131 141 151 161 171 181 191 2 12 22 32 42 52 62 72 82 92 102 112 122 132 142 152 162 172 182 192 3 13 23 33 43 53 63 73 83 93 103 113 123 133 143 153 163 173 183 193 4 14 24 34 44 54 64 74 84 94 104 114 124 134 144 154 164 174 184 194 5 15 25 35 45 55 65 75 85 95 105 115 125 135 145 155 165 175 185 195 6 16 26 36 46 56 66 76 86 96 106 116 126 136 146 156 166 176 186 196 7 17 27 37 47 57 67 77 87 97 107 117 127 137 147 157 167 177 187 197 8 18 28 38 48 58 68 78 88 98 108 118 128 138 148 158 168 178 188 198 9 19 29 39 49 59 69 79 89 99 109 119 129 139 149 159 169 179 189 199 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 -1.4000 -1.2090 -1.0181 -0.8271 -0.6362 -0.4452 -0.2543 -0.0633 0.1276 0.3186 0.5095 0.7005 0.8915 1.0824 1.2734 1.4643 1.6553 1.8462 2.0372 2.2281 -1.3809 -1.1899 -0.9990 -0.8080 -0.6171 -0.4261 -0.2352 -0.0442 0.1467 0.3377 0.5286 0.7196 0.9106 1.1015 1.2925 1.4834 1.6744 1.8653 2.0563 2.2472 -1.3618 -1.1709 -0.9799 -0.7889 -0.5980 -0.4070 -0.2161 -0.0251 0.1658 0.3568 0.5477 0.7387 0.9296 1.1206 1.3116 1.5025 1.6935 1.8844 2.0754 2.2663 -1.3427 -1.1518 -0.9608 -0.7698 -0.5789 -0.3879 -0.1970 -0.0060 0.1849 0.3759 0.5668 0.7578 0.9487 1.1397 1.3307 1.5216 1.7126 1.9035 2.0945 2.2854 -1.3236 -1.1327 -0.9417 -0.7508 -0.5598 -0.3688 -0.1779 0.0131 0.2040 0.3950 0.5859 0.7769 0.9678 1.1588 1.3497 1.5407 1.7317 1.9226 2.1136 2.3045 -1.3045 -1.1136 -0.9226 -0.7317 -0.5407 -0.3497 -0.1588 0.0322 0.2231 0.4141 0.6050 0.7960 0.9869 1.1779 1.3688 1.5598 1.7508 1.9417 2.1327 2.3236 -1.2854 -1.0945 -0.9035 -0.7126 -0.5216 -0.3307 -0.1397 0.0513 0.2422 0.4332 0.6241 0.8151 1.0060 1.1970 1.3879 1.5789 1.7698 1.9608 2.1518 2.3427 -1.2663 -1.0754 -0.8844 -0.6935 -0.5025 -0.3116 -0.1206 0.0704 0.2613 0.4523 0.6432 0.8342 1.0251 1.2161 1.4070 1.5980 1.7889 1.9799 2.1709 2.3618 -1.2472 -1.0563 -0.8653 -0.6744 -0.4834 -0.2925 -0.1015 0.0894 0.2804 0.4714 0.6623 0.8533 1.0442 1.2352 1.4261 1.6171 1.8080 1.9990 2.1899 2.3809 -1.2281 -1.0372 -0.8462 -0.6553 -0.4643 -0.2734 -0.0824 0.1085 0.2995 0.4905 0.6814 0.8724 1.0633 1.2543 1.4452 1.6362 1.8271 2.0181 2.2090 2.4000
It is entirely possible that I do not understand correctly, in which case, can you please clarify what you want to do? Specifically, how is x related to your matrices?

3 commentaires

salim sak
salim sak le 29 Jan 2022
my matrix is 60*200. and i am using imagesc to visualize this matrix. Every thing is ok with image. i just want change xlim from [1 200] to [-1.4 2.4] without any changes in the image (just as scalling )
Oh, ok. In that case, you can set the XData of the image in imagesc():
imagesc(rand(60,200),'XData',[-1.4 2.4])
salim sak
salim sak le 29 Jan 2022
Thank you so much
it was a little that made a big difference

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by