ytick=[-10:5:70]; for i=1:length(ytick) if ytick==-10 yticklabel(i:i, 1:3) = [mi,b2str(ytick(i), '%3.0f') ]; in matlab

The given code has a syntax error. It should be modified as follows:

main.m
ytick = -10:5:70;
for i=1:length(ytick)
    if ytick(i)==-10
        yticklabel(i:i, 1:3) = ['mi', b2str(ytick(i), '%3.0f')];
    end
end
138 chars
7 lines

This code creates an array ytick with values ranging from -10 to 70 with an interval of 5. Next, a for loop is used to iterate over all the values in ytick. For each value, it is checked whether it is equal to -10. If it is equal to -10, the corresponding yticklabel value is set to 'mi' concatenated with the value of ytick(i) converted to a string using the b2str function with a format specifier of '%3.0f'.

Note that the code you provided does not declare yticklabel anywhere, so prior to running this code, you need to declare that variable either as an empty array (e.g., yticklabel = []), or as a pre-existing array of suitable size.

related categories

gistlibby LogSnag